有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

spring boot java。lang.IllegalStateException:未找到WebApplicationContext:未找到ContextLoaderListener或DispatcherServlet注册错误

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

  1. # 1 楼答案

    我添加了侦听器并创建了applicationContext。来自现有appContext的xml。xml在/META-INF/Spring文件夹中,但当我尝试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>
    

    网络。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