如何在不同的端口上运行@RestController? [英] How to run @RestController on a different port?

查看:46
本文介绍了如何在不同的端口上运行@RestController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 spring-rest 创建一些 @RestController servlet.该应用程序不是在网络服务器上运行,而是作为一个带有嵌入式 tomcat 的简单命令行工具.

I'm using spring-rest to create some @RestController servlets. The application is not run on a webserver, but as a simple command line tool with embedded tomcat.

它们中的大多数应该在使用 server.port=80 属性指定的公共端口上运行.

Most of them should be running on a public port, which is specified using server.port=80 property.

问题:如何在不同的端口上运行不同的 @RestController?以至于其中一些只能在内部访问?

Question: how can I run different @RestController on different ports? So that some of them are only accessibly internally?

@RestController 
@RequestMapping("test")
public class TestServlet {

    @RequestMapping(value = "/", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public String test() { return "OK"; }
}

推荐答案

我建议使用代理.它可以是 Apache Web Server 或 Ngix.您需要在网络服务器中配置两个虚拟主机(在不同的端口).并将调用重定向到您的 tomcat 服务器.您可以在不同的路径中加载控制器,以便更轻松地代理来自 weberver 的调用.

I would recommend to use a proxy. It could be an Apache Web Server, or Ngix. You need to configure the two virtualhosts (in different ports) in the webserver. And redirect the invocation to your tomcat server. You can load your controllers in differents paths so it'll easier to proxyfy the calls from the weberver.

最后,您的客户端通过 Web 服务器进行调用,而不是直接调用 tomcat.

Finally your clients make the invocation through the web server, not directly to tomcat.

这篇关于如何在不同的端口上运行@RestController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆