Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 重写SpringMVC上下文配置位置会生成错误_Java_Xml_Spring_Spring Mvc_Tcserver - Fatal编程技术网

Java 重写SpringMVC上下文配置位置会生成错误

Java 重写SpringMVC上下文配置位置会生成错误,java,xml,spring,spring-mvc,tcserver,Java,Xml,Spring,Spring Mvc,Tcserver,当我尝试初始化我的应用程序时,我总是会遇到这个错误(它看起来工作正常,但令人不安) 我已经在Web服务器的context.xml中设置了配置文件的位置,如图所示(这在带有tc server 2.7的SpringSource ToolSuite 2.9.2中) WEB-INF/WEB.xml 可以在此处找到web.xml文件 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org

当我尝试初始化我的应用程序时,我总是会遇到这个错误(它看起来工作正常,但令人不安)

我已经在Web服务器的
context.xml
中设置了配置文件的位置,如图所示(这在带有tc server 2.7的SpringSource ToolSuite 2.9.2中)


WEB-INF/WEB.xml
可以在此处找到web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
  </context-param>
  <filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    <init-param>
      <param-name>sessionFactoryBeanName</param-name>
      <param-value>sessionFactory</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter>
    <filter-name>CharacterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter>
    <filter-name>HttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>
  <filter>
    <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
    <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>HttpMethodFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

上下文配置位置
/WEB-INF/spring/root-context.xml
冬眠过滤器
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
sessionFactoryBeanName
会话工厂
冬眠过滤器
/*
字符编码滤波器
org.springframework.web.filter.CharacterEncodingFilter
编码
UTF-8
强制编码
真的
HttpMethodFilter
org.springframework.web.filter.hiddenhttmpmethodfilter
Spring OpenEntityManager视图过滤器
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
字符编码滤波器
/*
HttpMethodFilter
/*
Spring OpenEntityManager视图过滤器
/*
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
org.springframework.web.context.ContextLoaderListener
appServlet
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/spring/appServlet/servlet-context.xml
1.
appServlet
/
以及在此处找到的根上下文文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:security="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <interceptors>
        <beans:bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"/>
    </interceptors>

    <beans:bean class="org.springframework.ui.context.support.ResourceBundleThemeSource" id="themeSource"/>
    <beans:bean class="org.springframework.web.servlet.theme.CookieThemeResolver" id="themeResolver" 
                p:cookieName="theme" p:defaultThemeName="default"/>

    <!-- Support for multipart form data as parameters to controllers -->
    <!-- NOTE: the maxUploadSize limit, we must be aware of DB sizes and increase this if necessary -->
    <beans:bean id="multipartResolver" p:maxInMemorySize="5000000"
            class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
            p:maxUploadSize="150000000"/>

    <!-- Resolves views selected for rendering by @Controllers to .jspx resources in the /WEB-INF/views directory -->
    <!-- 
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jspx" />
    </beans:bean>
     -->

    <!-- Tiles Configuration -->
    <beans:bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" id="tilesViewResolver">
        <beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
    </beans:bean>




    <beans:bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" id="tilesConfigurer">
        <beans:property name="definitions"> 
            <beans:list>
                <beans:value>/WEB-INF/layouts/layouts.xml</beans:value> 
                <!-- Scan views directory for Tiles configurations --> 
                <beans:value>/WEB-INF/views/**/views.xml</beans:value>
            </beans:list> 
        </beans:property>
    </beans:bean>

    <context:component-scan base-package="com.kwhours.mango.web.controller" />

    <beans:import resource="classpath:mango-app-context.xml"/>

    <beans:import resource="classpath:mango-app-security.xml"/>

    <context:component-scan base-package="com.kwhours.mango.service.jpa"/>



</beans:beans>

/WEB-INF/layouts/layouts.xml
/WEB-INF/views/**/views.xml

所以我想弄明白的是为什么contextLoaderListener无法找到位于指定目录下的这个文件。是否需要以某种方式将其提供给其他地方的contextLoaderListener?

查看异常堆栈跟踪:

Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/spring-mango/root-context.xml
您的应用程序正在查找文件/WEB-INF/spring mango/root-context.xml,但您的WEB.xml中引用了以下内容:

  • /WEB-INF/spring/root-context.xml
  • /WEB-INF/spring/appServlet/servlet-context.xml
但是context.xml中有以下内容:

<Parameter name="contextConfigLocation" value="/WEB-INF/spring-mango/root-context.xml" override="false"/>


那么,您的应用程序打算寻找什么呢?也许您需要删除context.xml中的条目。

因为根本原因是
文件未找到
,所以我打赌该文件实际上并不是您认为的位置。你是如何建立你的战争的?你看了部署战争中的文件了吗?我做了一场战争,看了文件,文件就在这个位置。
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/spring-mango/root-context.xml
<Parameter name="contextConfigLocation" value="/WEB-INF/spring-mango/root-context.xml" override="false"/>