我想在同一个应用程序中运行 spring boot 管理服务器和客户端。我更改了服务器端口,当我更改服务器端口时,spring admin 将访问我更改的端口。这样我就可以运行管理服务器。但我看不到我的网络应用程序页面。
我需要这样的输出。
本地主机:8080/myapplication(我的客户端应用程序)
localhost:8090/admin (Spring Boot 管理服务器)
这是一个在管理客户端和服务器客户端的两个不同端口上运行应用程序的简单示例。
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplicationBuilder parentBuilder = new SpringApplicationBuilder(Application.class);
parentBuilder.child(ServiceOneConfiguration.class).properties("server.port:8081").run(args);
parentBuilder.child(ServiceTwoConfiguration.class).properties("server.port:8082").run(args);
}
@Service
static class SharedService {
public String getMessage(String name) {
return String.format("Hello, %s, I'm shared service", name);
}
}
@Configuration
@EnableAutoConfiguration
static class ServiceOneConfiguration {
@Controller
@RequestMapping("/server")
static class ControllerOne {
@Autowired
private SharedService service;
@RequestMapping(produces = "text/plain;charset=utf-8")
@ResponseBody
public String getMessage(String name) {
return "ControllerOne says \"" + service.getMessage(name) + "\"";
}
}
}
@Configuration
@EnableAutoConfiguration
static class ServiceTwoConfiguration {
@Bean
EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
tomcat.setUriEncoding("cp1251");
return tomcat;
}
@Controller
@RequestMapping("/client")
static class ControllerTwo {
@Autowired
private SharedService service;
@RequestMapping(produces = "text/plain;charset=utf-8")
@ResponseBody
public String getMessage(String name) {
return "ControllerTwo says \"" + service.getMessage(name) + "\"";
}
}
}
}
有关更多详细信息,这里有一个链接:弹簧启动连接器 https://github.com/dddpaul/spring-boot-connectors希望这会有所帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)