Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.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/2/spring/14.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 需要了解spring配置文件的帮助吗_Java_Spring_Spring Mvc - Fatal编程技术网

Java 需要了解spring配置文件的帮助吗

Java 需要了解spring配置文件的帮助吗,java,spring,spring-mvc,Java,Spring,Spring Mvc,我正在研究一个现有的SpringMVC3项目,在查看Spring和上下文配置文件时,我感到困惑,请清除它或建议我是否有问题 Upadteroot context.xmlfile <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.spring

我正在研究一个现有的SpringMVC3项目,在查看Spring和上下文配置文件时,我感到困惑,请清除它或建议我是否有问题

Upadte
root context.xml
file

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- Root Context: defines shared resources visible to all other web components -->

    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>classpath:messages</value>   
            </list>
        </property> 
        <property name="defaultEncoding" value="UTF-8" />
    </bean>

    <bean id="localeChangeInterceptor"
        class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang" />
    </bean>

    <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
        <property name="defaultLocale" value="en" />        
    </bean>


   <bean id="themeSource" class="org.springframework.ui.context.support.ResourceBundleThemeSource">
        <property name="basenamePrefix" value="detailtheme-" />
    </bean>
    <bean id="themeResolver" class="org.springframework.web.servlet.theme.CookieThemeResolver">
        <property name="defaultThemeName" value="en" />
    </bean>


<!-- Helper bean to load all properties files -->
    <bean id="LoadPropertiesFiles" class="org.commons.utilities.LoadPropertiesFileHelper"
        init-method="loadPropertiesFileMethod" lazy-init="false" />
</beans>
为什么定义了同一类的两个bean,这是错误的吗?如果不是,那么在
root context.xml
servlet context.xml
中定义的bean的工作是什么

以下是
web.xml
供参考:

<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_2_5.xsd" version="2.5">
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
  </context-param>
  <!-- Listener to prevent class loader leaks -->
  <listener>
     <listener-class>se.jiderhamn.classloader.leak.prevention.ClassLoaderLeakPreventor</listener-class>
  </listener>  
  <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>
      <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-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
    <jsp-config>
        <taglib>
            <taglib-uri>/tagTld</taglib-uri>
            <taglib-location>/resources/tld/EnumTag.tld</taglib-location>
        </taglib>
    </jsp-config>
</web-app>

上下文配置位置
/WEB-INF/spring/root-context.xml
se.jiderhamn.classloader.leak.prevention.classloader防泄漏器
org.springframework.web.context.ContextLoaderListener
appServlet
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/spring/appServlet/servlet-context.xml
1.
appServlet
/
字符编码滤波器
org.springframework.web.filter.CharacterEncodingFilter
编码
UTF-8
强制编码
真的
字符编码滤波器
/*
网站
org.sitemesh.config.ConfigurableSiteMeshFilter
网站
/*
/塔格尔德
/资源/tld/EnumTag.tld

事实上,这个bean定义不属于根上下文,因此您可以安全地删除在
根上下文.xml
中定义的bean定义,并将其保留在
servlet上下文.xml


至于
paramName
参数,这是将用于更改区域设置的请求参数的名称-。

事实上,此bean定义不属于根上下文,因此您可以安全地删除
root context.xml
中定义的bean定义,只需将其保留在
servlet context.xml
中即可


至于
paramName
参数,这是将用于更改区域设置的请求参数的名称-。

事实上,此bean定义不属于根上下文,因此您可以安全地删除
root context.xml
中定义的bean定义,只需将其保留在
servlet context.xml
中即可


至于
paramName
参数,这是将用于更改区域设置的请求参数的名称-。

事实上,此bean定义不属于根上下文,因此您可以安全地删除
root context.xml
中定义的bean定义,只需将其保留在
servlet context.xml
中即可


至于
paramName
参数,这是将用于更改区域设置的请求参数的名称-。

LocaleChangeInterceptor
将拦截对web应用程序的web请求,并查找名为
lang
(例如)的查询参数,并尝试相应地设置应用程序的区域设置,以便您可以对web应用程序进行本地化

就两个文件
root context.xml
servlet context.xml
而言,第一个文件由
org.springframework.web.context.ContextLoaderListener使用,第二个文件由
org.springframework.web.servlet.DispatcherServlet
使用

ContextLoaderListener
可用于初始化Spring,即使您不一定使用Spring MVC。
DispatcherServlet
是Spring MVC特有的,如果您正在使用它,则需要它


可以去掉
根上下文.xml
,但这将要求您检查应用程序的设计,因为可能存在依赖于定义的bean的非SpringMVC组件
根上下文。xml
LocaleChangeInterceptor
将拦截对您的web应用程序的web请求,然后查找名为
lang
(例如)的查询参数,并尝试相应地设置应用程序的区域设置,以便您可以对web应用程序进行本地化

就两个文件
root context.xml
servlet context.xml
而言,第一个文件由
org.springframework.web.context.ContextLoaderListener使用,第二个文件由
org.springframework.web.servlet.DispatcherServlet
使用

ContextLoaderListener
可用于初始化Spring,即使您不一定使用Spring MVC。
DispatcherServlet
是Spring MVC特有的,如果您正在使用它,则需要它


可以去掉
根上下文.xml
,但这将要求您检查应用程序的设计,因为可能存在依赖于定义的bean的非SpringMVC组件
根上下文。xml
LocaleChangeInterceptor
将拦截对您的web应用程序的web请求,然后查找名为
lang
(例如)的查询参数,并尝试相应地设置应用程序的区域设置,以便您可以对web应用程序进行本地化

就两个文件
root context.xml
servlet context.xml
而言,第一个文件由
org.springframework.web.context.ContextLoaderListener使用,第二个文件由
org.springframework.web.servlet.DispatcherServlet
使用

ContextLoaderListener
可用于初始化Spring,即使您不一定使用Spring MVC。
DispatcherServlet
是Spring MVC特有的,如果您正在使用它,则需要它


可以去掉
根上下文.xml
,但这将要求您检查应用程序的设计,因为可能存在依赖于定义的bean的非SpringMVC组件
根上下文。xml
LocaleChangeInterceptor
将拦截对您的web应用程序的web请求,然后查找名为
lang
(例如)的查询参数,并尝试相应地设置应用程序的区域设置,以便进行本地化
<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_2_5.xsd" version="2.5">
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
  </context-param>
  <!-- Listener to prevent class loader leaks -->
  <listener>
     <listener-class>se.jiderhamn.classloader.leak.prevention.ClassLoaderLeakPreventor</listener-class>
  </listener>  
  <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>
      <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-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
    <jsp-config>
        <taglib>
            <taglib-uri>/tagTld</taglib-uri>
            <taglib-location>/resources/tld/EnumTag.tld</taglib-location>
        </taglib>
    </jsp-config>
</web-app>