我有一个使用嵌入式 tomcat 网络服务器并通过它的 SDK使用OpenKM的 spring-boot 2.1.2.RELEASE 应用程序。
现在,我有一些使用restassured
lib 进行 REST 调用和验证响应结构的集成测试。我的想法是集成OpenKM.war
到这个 wmbedded 的 tomcat 中,并且能够运行这个测试,而不需要在一些不同的服务器上运行 openkm 应用程序。
这就是我制作嵌入式 tomcat 来读取和部署 openkm.war 的方式:
@Configuration
public class TomcatConfig {
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
@Override
protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) {
new File(tomcat.getServer().getCatalinaBase(), "webapp").mkdirs();
try {
tomcat.addWebapp("/okm", new ClassPathResource("webapp/openkm.war").getFile().toString());
} catch (Exception ex) {
throw new IllegalStateException("Failed to add okm", ex);
}
return super.getTomcatWebServer(tomcat);
}
};
tomcat.addAdditionalTomcatConnectors(redirectConnector());
return tomcat;
}
private Connector redirectConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(8080);
connector.setSecure(false);
connector.setRedirectPort(8443);
return connector;
}
}
deploy 比在 openkm 附带的独立 tomcat webserver 上花费的时间更长,但它可以部署。
但是部署过程失败:
IOException parsing XML document from URL [file:/tmp/tomcat.2352216859213135410.8080/openkm.xml]; nested exception is java.io.FileNotFoundException: /tmp/tomcat.2352216859213135410.8080/openkm.xml (No such file or directory)
我在 openkm.war 文件旁边有这个文件(加上 server.xml、context.xml),但似乎嵌入式 tomcat 不知道它。
所有这些文件都位于src/main/resources/webapp
.
所以,我想知道我缺少什么配置,或者是否还有其他更好的方法来实现我想要的?