dis*_*ame 9 tomcat spring-boot
我有一个server依赖于web模块的模块:
<dependency>
<groupId>org.ema.server</groupId>
<artifactId>web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这是spring-boot-maven-plugin为了获得一个独立的重新打包:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>org.ema.server.Server</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
到目前为止一切正常.该web模块将被包含在最终的jar中BOOT-INF/lib/web-0.0.1-SNAPSHOT.war.
我知道Spring允许在运行时为Tomcat加载额外的war文件,但是看起来这样的war文件必须位于文件系统的某个地方,否则我做错了.
问题是我如何保持独立的感觉,但仍然能够将war文件添加到我的最终独立jar并将它们部署到内置的Tomcat?
下面的代码显示了如何做到这一点,但我不确定它是否可以按我要求的方式完成:
@Bean
public EmbeddedServletContainerFactory servletContainerFactory() {
LOGGER.info("Adding web app");
return new TomcatEmbeddedServletContainerFactory() {
@Override
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
// Ignore that since it's not working anyway.
String resourcePath = getClass().getResource("/../lib/web-0.0.1-SNAPSHOT.war").getPath().toString();
try {
tomcat.addWebapp("/web", resourcePath);
} catch (ServletException ex) {
throw new IllegalStateException("Failed to add webapp", ex);
}
return super.getTomcatEmbeddedServletContainer(tomcat);
}
};
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
539 次 |
| 最近记录: |