I have a war archive with a web application. I want to start that application within my Spring Boot application. I therefore followed the advice from that question:
@Bean
public EmbeddedServletContainerFactory servletContainerFactory() {
return new TomcatEmbeddedServletContainerFactory() {
@Override
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
try {
tomcat.addWebapp("blog", "/tmp/roller.war");
} catch (ServletException ex) {
throw new IllegalStateException("Failed to add webapp", ex);
}
return super.getTomcatEmbeddedServletContainer(tomcat);
}
};
}
That works quite well, except the war doesn't get extracted:
Unable to create the directory [/tmp/tomcat.9153500015669016883.8080/webapps/blog]
That's the layout of the tomcat working directory:
$ find /tmp/tomcat.9153500015669016883.8080/
/tmp/tomcat.9153500015669016883.8080/
/tmp/tomcat.9153500015669016883.8080/work
/tmp/tomcat.9153500015669016883.8080/work/Tomcat
/tmp/tomcat.9153500015669016883.8080/work/Tomcat/localhost
/tmp/tomcat.9153500015669016883.8080/work/Tomcat/localhost/blog
/tmp/tomcat.9153500015669016883.8080/work/Tomcat/localhost/ROOT
A breakpoint in ExpandWar.expand()
reveils that it wants to create a directory in webapps/. This non existing webapps folder is taken from Host.getAppBaseFile()
(which comes from the ContextConfig.context
).
So for me it looks like something is weird configured and it should be expanded into work/Tomcat/localhost/blog. How can I do that?
It seems that this is not spring related, but expected behaviour of an embedded tomcat. I found this related issue:
So simply creating the default appBase directory before deployment does the trick: