我正在尝试从现有应用程序运行另一个Spring启动服务,并按顺序使用相同的数据库层。 这两个应用程序应该是带有不同端口的不同服务。
我的项目结构如下:
- com.name (Project A)
| - Application
| - com.name.controller
- com.name.controller2 (New) (Project B)
| - Application2 (New)
| - com.name.controller2.controller (New RestController)
|
- com.name.storage (Project C)
|
|
- com.name.service
对于应用程序:(它从所有控制器端点开始)
@SpringBootConfiguration
public class Application {
SpringApplication.run(Application.class, args);
}
对于Application2,我试过没有运气:
//@SpringBootApplication(
// scanBasePackages={"com.name"})
@SpringBootConfiguration
@ComponentScan(basePackages = {"com.name"})
public class Application2{
SpringApplication.run(Application2.class, args);
}
我尝试了很多变化,但无法做到正确。 如果我使用“com.name.storage”作为basePackages应用程序开始时根本没有配置(不识别它的控制器的其余端点),而是监听新端口。
你能帮我正确配置吗?
答案 0 :(得分:0)
尝试这样的事情
SpringApplicationBuilder uws = new SpringApplicationBuilder(UserWebApplication.class)
.properties("server.port=8081",
"server.contextPath=/UserService");
uws.run();
SpringApplicationBuilder pws = new SpringApplicationBuilder(ProjectWebApplication.class)
.properties("server.port=8082",
"server.contextPath=/ProjectService");
pws.run();