简体   繁体   中英

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener or DispatcherServlet registered error

I am using Spring, Gradle, and Tomcatrunwar for this project, and I keep facing this error.. I have tried different solutions online, but none helped. I just joined the project recently and I am relatively new to servelets My 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

I added the listener and created applicationContext.xml from an existing appContext.xml in a /META-INF/Spring folder but that creates a bunch of new errors when I try gradlew tomCatRunWar task applicationContext.xml

<!--

    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements. See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership. The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License. You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied. See the License for the
    specific language governing permissions and limitations
    under the License.

-->

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:sec="http://www.springframework.org/schema/security"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:cache="http://www.springframework.org/schema/cache"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">

    <sec:global-method-security
            pre-post-annotations="enabled" />

    <tx:annotation-driven />

    <context:component-scan
            base-package="org.apache.fineract.accounting.*,
                                          org.apache.fineract.commands.provider,
                                          org.apache.fineract.commands.handler,
                                          org.apache.fineract.commands.service,
                                          org.apache.fineract.commands.*,
                                          org.apache.fineract.accounting.*,
                                          org.apache.fineract.infrastructure.*,
                                          org.apache.fineract.scheduledjobs.*,
                                          org.apache.fineract.organisation.*,
                                          org.apache.fineract.portfolio.loanaccount.*,
                                          org.apache.fineract.portfolio.savings.*,
                                          org.apache.fineract.portfolio.*,
                                          org.apache.fineract.useradministration.*,
                                          org.apache.fineract.mix.*,
                                          org.apache.fineract.template.*,
                                          org.apache.fineract.template.service,
                                          org.apache.fineract.batch">
        <context:exclude-filter expression="org.springframework.stereotype.Controller"
                                type="annotation" />

        <!-- We do NOT want all @Configuration "beans" to be auto-detected by ComponentScan,
             but we want to use / import them explicitly in Tests & Spring Boot applications,
             or other import in other @Configuration, so that we could have mutually exclusive ones.
         -->
        <context:exclude-filter expression="org.springframework.context.annotation.Configuration"
                                type="annotation" />
    </context:component-scan>

    <bean id="auditorAware"
          class="org.apache.fineract.infrastructure.core.domain.AuditorAwareImpl" />
    <jpa:auditing auditor-aware-ref="auditorAware" />

    <jpa:repositories base-package="org.apache.fineract.commands.domain" />
    <jpa:repositories base-package="org.apache.fineract.infrastructure.*.domain" />
    <jpa:repositories base-package="org.apache.fineract.accounting.*.domain" />
    <jpa:repositories base-package="org.apache.fineract.useradministration.domain" />
    <jpa:repositories base-package="org.apache.fineract.organisation.*.domain" />
    <jpa:repositories base-package="org.apache.fineract.portfolio.*" />
    <jpa:repositories base-package="org.apache.fineract.mix.domain" />
    <jpa:repositories base-package="org.apache.fineract.scheduledjobs.*" />
    <jpa:repositories base-package="org.apache.fineract.template.domain" />

    <import resource="infrastructure.xml" />

    <import resource="securityContext.xml" />

    <import resource="cache.xml" />

    <bean id="applicationEventMulticaster" class="org.springframework.context.event.SimpleApplicationEventMulticaster">
        <property name="taskExecutor">
            <bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
        </property>
    </bean>

    <import resource="spmContext.xml"/>
</beans>

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">

    <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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM