我想在同一应用程序中运行spring boot admin服务器和客户端。我更改了服务器端口,当我更改服务器端口时,spring admin将访问更改后的端口。这样我就可以运行管理服务器。但是我看不到我的Web应用程序页面。
我需要这样的输出。
Localhost:8080 / myapplication(我的客户端应用程序)
本地主机:8090 / admin(Spring Boot管理服务器)
答案 0 :(得分:1)
这是一个简单的示例,用于在管理客户端和服务器客户端的两个不同端口上运行应用程序。
@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 希望这会有所帮助。
答案 1 :(得分:-1)
我们可以为此使用spring boot multi模块。我使用了带有2个模块的Spring Boot多功能模块。
import logging
tf.logging.set_verbosity(tf.logging.INFO)