java - Need help to understand spring config files -
i studying existing spring mvc 3 project, while looking spring , context config files confused, please clear or suggest me if wrong.
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 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 load properties files --> <bean id="loadpropertiesfiles" class="org.commons.utilities.loadpropertiesfilehelper" init-method="loadpropertiesfilemethod" lazy-init="false" /> </beans>
here don't understand lang
? understand it's veriable name value assigned paramname
(default_param_name
), don't understand how value assigned lang
because don't find single location value (like en,hi..etc) set.
the confusing thing 1 more bean same class defined in servlet-context.xml
:
<mvc:interceptors> <beans:bean class="org.springframework.web.servlet.i18n.localechangeinterceptor"> <beans:property name="paramname" value="lang" /> </beans:bean> ... </mvc:interceptors>
why two beans of same class defined, wrong? if not, work of bean defined in root-context.xml
, servlet-context.xml
?
below web.xml
reference:
<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 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>
localechangeinterceptor
intercept web requests web app, , query param name lang
(e.g. http://mywebapp.com/login?lang=en), , try set app's locale accordingly can localization of web app.
as far 2 files root-context.xml
, servlet-context.xml
concerned - first file being used <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>
, second file being used org.springframework.web.servlet.dispatcherservlet
.
contextloaderlistener
can used initialize spring when not using spring mvc. dispatcherservlet
specific spring mvc , needed if making use of it.
it may possible rid of root-context.xml
, require review design of app there may non-springmvc components depend on beans defined root-context.xml
.
Comments
Post a Comment