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

标签 java spring-boot spring-mvc tomcat gradle

我在这个项目中使用了 Spring、Gradle 和 Tomcatrunwar,但我一直面临这个错误。我在网上尝试了不同的解决方案,但都没有帮助。我最近刚加入这个项目,我对 servelets 比较陌生 我的 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

最佳答案

我添加了监听器并从/META-INF/Spring 文件夹中的现有 appContext.xml 创建了 applicationContext.xml 但是当我尝试 gradlew tomCatRunWar 任务时会产生一堆新错误 应用上下文.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

关于java.lang.IllegalStateException : No WebApplicationContext found: no ContextLoaderListener or DispatcherServlet registered error 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59221780/

相关文章:

hibernate - 改变Hibernate 5命名策略+spring boot+注解

java - 在 Spring-Boot 中配置 bean

java - jni/java : thread safe publishing/sharing of effectively immutable native object

java - 使用 Velocity 与 Java 结合使用,我尝试从 '.' 分隔字符串中提取单个字段

java - Spring Controller 不被视为单例

spring saml - IDP 发起的 SSO

java - Spring:保存登录的用户 session

java - 在哪里声明具有多个服务的 JDO Singleton PersistenceManagerFactory

java - Imageloader 几张图像到 ViewPager

mysql - 父级有子级列表。数据库中子项的单个记录。但在调试时它显示 2 个具有相同 id 的记录