java.lang.IllegalStateException:找不到WebApplicationContext:没有ContextLoaderListener或DispatcherServlet注册的错误

时间:2019-12-06 23:56:50

标签: java spring-boot spring-mvc tomcat gradle

我正在为该项目使用Spring,Gradle和Tomcatrunwar,并且一直遇到此错误。.我在线尝试了不同的解决方案,但没有帮助。我最近才刚加入这个项目,对Servets还是比较陌生 我的web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="fineract-platform-provider" version="3.0">


    <display-name>Fineract Platform</display-name>
    <filter>
        <filter-name>filterChainProxy</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter>
        <filter-name>filterChainProxy2</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter>
        <filter-name>filterChainProxy3</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>filterChainProxy</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>filterChainProxy2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>filterChainProxy3</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <description>A provider of microfinance services which applications can
        consume once authenticated and authorized.</description>

    <!--  =========================================================================
            web.xml is no longer used since the switch to Spring Boot.

            org.apache.fineract.infrastructure.core.boot.war.WebApplicationInitializerConfiguration
            and org.apache.fineract.infrastructure.core.boot.WebXmlConfiguration take its place now.
          =========================================================================
      -->
    <absolute-ordering/>
</web-app>```

I don't have a applicationContext.xml in my project, the IDE creates the spring application context and I can't access the file. So adding a listener for the ContextLoader points that out in a new error,
What can I do, please advice

1 个答案:

答案 0 :(得分:0)

我添加了侦听器,并从/ META-INF / Spring文件夹中的现有appContext.xml中创建了applicationContext.xml,但是当我尝试gradlew tomCatRunWar任务时,这会产生许多新错误 applicationContext.xml



<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="fineract-platform-provider" version="3.0">

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <context-param>
        <param-name>appContext</param-name>
        <param-value>/META-INF/spring/appContext.xml</param-value>
    </context-param>
   <!--
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
-->


    <display-name>Fineract Platform</display-name>
    <filter>
        <filter-name>filterChainProxy</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter>
        <filter-name>filterChainProxy2</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter>
        <filter-name>filterChainProxy3</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>filterChainProxy</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>filterChainProxy2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>filterChainProxy3</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <description>A provider of microfinance services which applications can
        consume once authenticated and authorized.</description>


    <!--  =========================================================================
            web.xml is no longer used since the switch to Spring Boot.

            org.apache.fineract.infrastructure.core.boot.war.WebApplicationInitializerConfiguration
            and org.apache.fineract.infrastructure.core.boot.WebXmlConfiguration take its place now.
          =========================================================================
      -->


    <absolute-ordering/>
</web-app>```


Link to log file https://docs.google.com/document/d/1OD5XpoJ5JMTbeGMhYelvZWrulIAXe-dDOpGJPsfv-nc/edit?usp=sharing

Web.xml

android:usesCleartextTraffic="true"