如何在同一应用程序中运行 Spring Boot 管理客户端和服务器 [英] How to run spring boot admin client and server in same application
问题描述
我想在同一个应用程序中运行 spring boot 管理服务器和客户端.我更改了服务器端口,当我更改服务器端口时,spring admin 将访问我更改的端口.所以我可以运行管理服务器.但我看不到我的网络应用程序页面.
I want to run a spring boot admin server and client inside the same application.I changed server port, when I change the server port spring admin will access my changed port. so I can run an admin server. but I can't see my web application pages.
我需要这样的输出.
Localhost:8080/myapplication(我的客户端应用程序)
localhost:8090/admin (spring boot 管理服务器)
Localhost:8080/myapplication (my client application)
localhost:8090/admin (spring boot admin server)
推荐答案
这里是一个简单的例子,在两个不同的端口上为管理客户端和服务器客户端运行应用程序.
Here is a simple example to run the application on two different ports for admin client and for server client.
@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) + "\"";
}
}
}
}
欲知更多详情,请点击链接:spring-boot-connectors希望这会有所帮助.
For more detail here is a link: spring-boot-connectors Hope this will help.
这篇关于如何在同一应用程序中运行 Spring Boot 管理客户端和服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!