在我的项目

时间:2017-04-07 08:10:44

标签: spring-boot servlet-2.5

我是Spring Boot的新手,我正在尝试在我的项目中使用它,该项目配置了servlet 2.5。当我使用Eclipse Maven Plugin运行它时,目标是" spring-boot:run"执行返回以下错误:

`[Tomcat-startStop-1] ERROR o.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].TomcatEmbeddedContext[]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122) [na:1.8.0_60]
at java.util.concurrent.FutureTask.get(FutureTask.java:192) [na:1.8.0_60]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:939) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) [tomcat-embed-core-8.5.11.jar:8.5.11]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_60]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]

我的项目有一个父项和3个模块,其中一个孩子就是网络项目。

我的配置如下:

  • 在父母pom中:

    <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version> </parent> ... <properties> <springBoot.version>1.5.2.RELEASE</springBoot.version> </properties> ...

    </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${springBoot.version}</version> </dependency>
    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId>
    <version>${springBoot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-legacy</artifactId> <version>1.1.0.RELEASE</version> </dependency> </dependencies> </dependencyManagement>

- 在网络儿童pom:

`   <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-legacy</artifactId>
    </dependency>
</dependencies>
`
...
`
<plugins>
   <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
</plugins>
`   
  • 在web.xml中: <listener>
    <listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class> </listener>

1 个答案:

答案 0 :(得分:0)

spring-boot-legacy, 1.1.0.RELEASE仅保证与Spring Boot,1.4.2.RELEASE一起使用。

并非通常的Spring Boot中的所有功能都能正常工作。以编程方式定义的servlet过滤器和servlet(例如使用FilterRegistrationBean或ServletRegistrationBean)将不起作用,我认为这是由于Servlet 2.5的限制。显然,Servlet 3.0注释也不起作用(例如@WebServlet)

Tomcat 6支持Servlet 2.5。因此,Spring Boot遗留应用程序应该可以正常使用:

  

mvn tomcat6:运行

<plugin>
  <artifactId>tomcat6-maven-plugin</artifactId>
  <groupId>org.apache.tomcat.maven</groupId>
  <version>2.0</version>
</plugin>

同样重要的是,为 SpringBootContextLoaderListener 提供一些线索,了解在何处找到“ Application ”类(包含 @SpringBootApplication ),例如:

您的 web.xml 将包含以下内容:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>demo.Application</param-value>
</context-param>

一旦你理解了这些限制,那么工作真是太棒了!