我正在尝试加载一个“WAR”文件到Spring Boot的嵌入式tomcat服务器。为此,我找到了这样的答案:Spring Boot:如何向嵌入式Tomcat添加另一个WAR文件?
但是在我这样做之后,我发现在这个问题上已经问过的错误:用嵌入的Tomcat部署现有的war,但是没有一个满意的答案。
注意:我知道这是一个重复的问题(我把链接),但当时没有足够的声誉添加一个评论,或能力与作者私下联系,我看到了需要重复的问题希望一些不同的答案。
特别是,我正在尝试加载分配在spring boot项目的“resources/war/”文件夹中的芝麻war文件。
我的SpringBootApplication:
@SpringBootApplication
@ComponentScan("com.github.p4535992.mvc")
public class JspDemoApplication extends SpringBootServletInitializer implements WebApplicationInitializer{
public static void main(String[] args) {
SpringApplication.run(JspDemoApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(JspDemoApplication.class);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
SpringApplication.run(JspDemoApplication.class);
}
/*
* https://stackoverflow.com/questions/31374726/spring-boot-how-to-add-another-war-files-to-the-embedded-tomcat
* @return the {@link TomcatEmbeddedServletContainerFactory}.
*/
@Bean
public EmbeddedServletContainerFactory servletContainerFactory() {
return new TomcatEmbeddedServletContainerFactory() {
@Override
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
try {
//tomcat.addUser("tomcat", "tomcat");
//tomcat.addRole("tomcat", "manager-gui");
String webappDirLocation = System.getProperty("user.dir")+"/src/main/resources/war/";
//When the spring boot application is made of fat jar(=executable jar),
// the above code is not enough
Context context1 = tomcat.addWebapp("/sesame", new
File(webappDirLocation+"openrdf-sesame.war").getAbsolutePath());
Context context2 = tomcat.addWebapp("/workbench",new
File(webappDirLocation+"openrdf-workbench.war").getAbsolutePath());
WebappLoader loader = new WebappLoader(Thread.currentThread().getContextClassLoader());
context1.setLoader(loader);
context2.setLoader(loader);
} catch (ServletException ex) {
throw new IllegalStateException("Failed to add webapp", ex);
}
return super.getTomcatEmbeddedServletContainer(tomcat);
}
};
}
}
我的旧异常:old_exception
更新:
注意:我在Windows上工作只是为了澄清。
现在没有抛出异常,但是当我尝试调用地址http://localhost:8081/openrdf-sesame,http://localhost:8081/sesame的webapp时,我得到错误404资源找不到。
例如“状态”:404,“错误”:“找不到”,“消息”:“无消息可用”
所以现在看来war文件加载了,但我一定错过了web应用html" target="_blank">程序http url集上的某些内容。
更新2 Spring Boot的新application.java:
@SpringBootApplication
@ComponentScan("com.github.p4535992.mvc")
public class MainApp extends SpringBootServletInitializer implements WebApplicationInitializer{
public static void main(String[] args) {
SpringApplication.run(MainApp.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MainApp.class);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
//com.github.p4535992.mvc.component.ScheduledTasks --> Work
SpringApplication.run(MainApp.class);
}
@Bean
public EmbeddedServletContainerFactory servletContainerFactory() {
return new TomcatEmbeddedServletContainerFactory() {
@Override
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
try {
String webappDirLocation = "src/main/resources/war/";
tomcat.addWebapp("/sesame", new
File(webappDirLocation+"openrdf-sesame.war").getAbsolutePath());
tomcat.addWebapp("/workbench",new
File(webappDirLocation+"openrdf-workbench.war").getAbsolutePath());
} catch (ServletException ex) {
throw new IllegalStateException("Failed to add webapp", ex);
}
return super.getTomcatEmbeddedServletContainer(tomcat);
}
};
}
}
现在我有了一个新的例外:
2016-04-09_10:25:01.998 [Tomcat-startStop-1] ERROR org.apache.catalina.core.ContainerBase - A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
... 6 common frames omitted
Caused by: java.lang.IllegalStateException: java.lang.NullPointerException
at org.springframework.boot.context.embedded.tomcat.TomcatResources$Tomcat7Resources.addJar(TomcatResources.java:125)
at org.springframework.boot.context.embedded.tomcat.TomcatResources.addClasspathResources(TomcatResources.java:63)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory$StoreMergedWebXmlListener.onStart(TomcatEmbeddedServletContainerFactory.java:746)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory$StoreMergedWebXmlListener.lifecycleEvent(TomcatEmbeddedServletContainerFactory.java:737)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:95)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
... 6 common frames omitted
Caused by: java.lang.NullPointerException: null
at org.springframework.boot.context.embedded.tomcat.TomcatResources$Tomcat7Resources.addJar(TomcatResources.java:122)
... 13 common frames omitted
2016-04-09_10:06:32.378 [localhost-startStop-1] ERROR o.a.c.c.ContainerBase.[Tomcat].[localhost].[/sesame] - Servlet [jsp] in web application [/sesame] threw load() exception
java.lang.ClassNotFoundException: org.apache.jasper.servlet.JspServlet
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1308)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1142)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:518)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:499)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1102)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1038)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4997)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5289)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
2016-04-09_10:06:32.568 [localhost-startStop-1] ERROR o.a.c.c.C.[Tomcat].[localhost].[/workbench] - Servlet [jsp] in web application [/workbench] threw load() exception
java.lang.ClassNotFoundException: org.apache.jasper.servlet.JspServlet
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1308)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1142)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:518)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:499)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1102)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1038)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4997)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5289)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我试图解决添加maven依赖项的问题,但它不起作用:
<!-- Support for add war to the project -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.0.M4</version>
</dependency>
<!-- https://stackoverflow.com/questions/4501829/unable-to-load-class-for-jsp -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.2-b02</version>
<scope>provided</scope>
</dependency>
我发现在这个问题上已经问过的错误相同:使用嵌入式Tomcat部署现有war,但没有一个满意的答案。
因为这样的配置对Spring Boot没有意义。Spring Boot有两种选择:
更多信息请阅读Spring Boot文档的这一部分。
还要注意,您提到的问题与Spring/Spring Boot无关。
我试图加载一个"war"文件到Spring Boot的嵌入式tomcat服务器。为此,我找到了这个答案:Spring Boot:如何向嵌入式tomcat添加另一个WAR文件? 但在我这么做之后,我发现在这个问题上已经出现了同样的错误:使用嵌入式Tomcat部署现有的war,但没有令人满意的答案。 注意:我知道这可以被看作是一个重复的问题(我放了链接),但当时没有足够的声誉添加评论,或者没有能力私下
我正在尝试将外部war文件部署到spring boot的嵌入式tomcat中。我以.war文件的格式添加了gradle依赖项,我想用spring boot应用程序运行这个war,但不运行请任何人可以帮助我。
问题内容: Spring Boot的嵌入式tomcat非常便于开发和部署。 但是,如果应该添加另一个(第三方)WAR文件(例如GeoServer)怎么办? 也许以下是正常过程: 安装普通的Tomcat服务器。 将Spring Boot应用程序构建为WAR文件,并将其添加到Tomcat的webapps文件夹中。 还将另一个(第三方)WAR文件添加到webapps文件夹。 但是,如果可以进行以下配置,
我已经搜索了这个问题,但我没有找到任何关于这个案例的东西。我发现了很多“如何将Spring Boot WAR部署到Tomcat”,但是没有关于用Spring Boot包装现有的Tomcat WAR的内容。 我正在尝试用Spring Boot“包装器”包装一个现有的WAR,这样就不必重新配置现有的代码库。这个解决方案不起作用,因为它依赖于在绝对位置可用的WAR,而我们正试图将“应用程序”WAR打包在
我正在尝试获得一个Spring Bootjar,该jar具有嵌入式Tomcat服务器,以便在运行时加载一个外部war。我正在尝试使用本文中所展示的技术来实现这一点。 Spring Boot应用程序中的容器bean: 当我启动Spring Boot container应用程序时,container bean定位warfile并将其添加到类路径中,但随后抛出一个ClassNotFoundExcepti