weixin_43078650 2019-12-18 11:21 采纳率: 0%
浏览 757
已结题

spring boot 2外部tomcat启动错误:check whether you have multiple ContextLoader* definitions in your web.xml!

spring boot 2外部tomcat启动错误

java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!

pom:

 <!-- Spring Boot Dubbo 依赖 -->
       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <!-- <scope>compile</scope>-->
            <scope>provided</scope><!-- 必须要加,不然报错 -->
        </dependency>

<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-velocity</artifactId>-->
<!--            <version>1.2.2.RELEASE</version>-->
<!--        </dependency>-->

<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-legacy</artifactId>-->
<!--            <version>1.1.0.RELEASE</version>-->
<!--        </dependency>-->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.boot</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>0.2.0</version>
        </dependency>

web.xml检查过没有ContextLoaderListener,ContextLoaderListener和RequestContextListener写在代码中

@Configuration
public class ListenerConfig {

    /**
     * 配置 RequestContextListener
     * @return
     */
    @Bean
    public ServletListenerRegistrationBean<RequestContextListener> listenerRegistration1() {
        return new ServletListenerRegistrationBean<>(
            new RequestContextListener());
    }

    /**
     * 配置 ContextLoaderListener
     * @return
     */
    @Bean
    public  ServletListenerRegistrationBean<ContextLoaderListener> listenerRegistration2(){
        return new ServletListenerRegistrationBean<>(
            new ContextLoaderListener()
        );
    }
}

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2019-12-18 11:21
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?