首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

String有关配置一

2012-10-25 
String相关配置一?1、启动Web容器时,自动装配ApplicationContext的配置信息?listener??? listener-class

String相关配置一

?1、启动Web容器时,自动装配ApplicationContext的配置信息

?<listener>
??? <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
??? </listener>
? <listener>

?

或:

<servlet>
??? <servlet-name>context</servlet-name>
???? ?<servlet-class>
??????? ?org.springframework.web.context.ContextLoaderServlet
???? ?</servlet-class>
??? <load-on-startup>1</load-on-startup>
</servlet>

?

2、需要指定配置文件位置,可通过context-param加以指定:可以逗号分隔多多文件

?

?<context-param>
??<param-name>contextConfigLocation</param-name>
??<param-value>classpath*:spring/applicationContext.xml, /WEB-INF/MenuTrees.xml</param-value>
?</context-param>

?

?

3、

WebApplicationContextUtils.getWebApplicationContext方法在Web应用中获取ApplicationContext引用。 如:ApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext();
???????? LoginAction action=(LoginAction)ctx.getBean("LoginAction ");

?

?ServletContext servletContext = request.getSession().getServletContext();???
??????? ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
??????? return (DailyBalanceService) ctx.getBean("balanceService");

?

4、spring-mvc 的相关配置

?1、配置请求分发:

??? <servlet>
??????? <servlet-name>dispatcher</servlet-name>
??????? <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
??????? <init-param>
??????????? <param-name>contextConfigLocation</param-name>
??????????? <param-value>/WEB-INF/mvc-config/*.xml</param-value>
??????? </init-param>
??????? <load-on-startup>1</load-on-startup>
??? </servlet>

?

?<servlet-mapping>???????????????????????

??????? <servlet-name>Dispatcher</servlet-name>
??????? <url-pattern>*.do</url-pattern>
</servlet-mapping>

?

说明:1、DispatcherServlet 根据配置将请求分发给各逻辑处理单元;

???????? 2、请求映射 ,.do, .action等;

?

响应bean

?

??? <bean id="viewResolver" value="redirect:/Cart/ShowCart.do"/>
??? <property name="errorView" value="feifei/Cart/ShoppingCart"/>
??? <property name="presentRuleManager" ref="PresentRuleManager"/>
??? <property name="frontEnd" value="true"/>
? </bean>

?

或者:

1、?<bean id="urlMappingDocument"??? value="redirect:/Cart/ShowCart.do"/>
??? <property name="errorView" value="feifei/Cart/ShoppingCart"/>
??? <property name="presentRuleManager" ref="PresentRuleManager"/>
??? <property name="frontEnd" value="true"/>
? </bean>

?

?

热点排行