我有一个spring-boot 2.1.2.RELEASE应用程序,该应用程序使用嵌入式tomcat Web服务器并通过其SDK 使用OpenKM。
现在,我有一些集成测试,这些测试使用restassuredlib进行REST调用并验证响应结构。我的想法是将其集成OpenKM.war到此嵌入式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);
}
}; …Run Code Online (Sandbox Code Playgroud)