Spring boot 不';我无法在我的项目中使用Spring Boot legacy

Spring boot 不';我无法在我的项目中使用Spring Boot legacy,spring-boot,servlet-2.5,Spring Boot,Servlet 2.5,我是SpringBoot的新手,我正试图在配置了Servlet2.5的项目中使用它。当我使用Eclipse Maven插件以“spring boot:run”为目标运行它时,执行返回以下错误: `[Tomcat-startStop-1] ERROR o.apache.catalina.core.ContainerBase - A child container failed during start java.util.concurrent.ExecutionException: org.apa

我是SpringBoot的新手,我正试图在配置了Servlet2.5的项目中使用它。当我使用Eclipse Maven插件以“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个模块,其中一个是web项目

我的配置如下:

  • 在父pom中:

    
    org.springframework.boot
    spring启动程序父级
    1.5.2.1发布
    
    ...
    
    1.5.2.1发布
    

    
    org.springframework.boot
    SpringBootStarterWeb
    ${springBoot.version}
    
    org.springframework.boot 弹簧靴启动器tomcat
    ${springBoot.version} org.springframework.boot 弹簧靴遗产 1.1.0.1发布

-在web子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>
`   
`
org.springframework.boot
SpringBootStarterWeb
org.apache.tomcat.embed
汤姆卡特·贾斯珀
假如
org.springframework.boot
弹簧启动安全
org.springframework.boot
弹簧靴遗产
`
...
`
org.springframework.boot
springbootmaven插件
`   
  • 在web.xml中:

    org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener
仅保证与1.4.2.1版本的弹簧靴配合使用

并不是所有在普通弹簧靴中工作的东西都能工作。编程定义的servlet过滤器和servlet(例如使用FilterRegistrationBean或ServletRegistrationBean)将无法工作,我认为这是由于Servlet2.5中的限制。显然,Servlet 3.0注释也不起作用(例如@WebServlet)

Tomcat6支持Servlet2.5。因此,Spring Boot遗留应用程序应该可以通过以下方式正常工作:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>demo.Application</param-value>
</context-param>
mvn tomcat6:运行


tomcat6 maven插件
org.apache.tomcat.maven
2
另外,向SpringBootContextLoaderListener提供一些关于在何处查找“应用程序”类(包含@SpringBootApplication的类)的线索也很重要,例如:

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

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

上下文配置位置
演示应用程序

一旦你理解了这些局限性,你会惊奇地发现什么是有效的

当使用
springboot:run
运行时,您的web.xml将被忽略。解决方案是什么@M.DeinumYou需要将应用程序部署到应用服务器上,这正是遗留内容的用途。