web.xml中的一些配置事项的作用

 
 <context-param>
  	  <param-name>contextConfigLocation</param-name> 
  	  <param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>

在使用spring框架时,通常需要配置contextConfigLocation这个属性,如果在web.xml中不写任何参数配置信息,默认的路径是"/WEB-INF/applicationContext.xml,因为在spring加载时会去寻找这个属性对应的配置文件,从而获取到配置文件的路径,它可以配置多个以xml为后缀的文件,用逗号隔开。

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

作用:在启动Web容器时,自动装配Spring 在contextConfiguration属性配置的路径中的xml的配置信息。通过API可以看到它继承于contextLoader并实现了ServletContextListener,所以启动容器时,就会默认执行ServletContextListener实现的方法,在ContextLoaderListener中关联了ContextLoader这个类,因此整个加载配置过程将由ContextLoader来完成。

<filter>
 		<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
 		<filter-class>
 			org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
 		<init-param>
 			<!--
 				指定org.springframework.orm.jpa.LocalEntityManagerFactoryBean在spring配置文件中的名称,默认值为entityManagerFactory
 				如果LocalEntityManagerFactoryBean在spring中的名称不是entityManagerFactory,该参数一定要指定,否则会出现找不到entityManagerFactory的例外
 			-->
 			<param-name>entityManagerFactoryBeanName</param-name>
 			<param-value>entityManagerFactory</param-value>
 		</init-param>
 	</filter>

在使用Hibernate和Spring框架的项目中经常会遇到LazyInitializationException的异常,而openEntityManagerInViewFilter就是专门解决这种由于session关闭而出现延迟加载的错误的。当配置了这个属性之后,session不在是执行了相应数据库操作之后就关闭了,而是直到整个view层的相关调用后才关闭session连接。
<filter>
 		<filter-name>struts2</filter-name>
 		<filter-class>
 			org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
 	</filter>
 
 	<filter-mapping>
 		<filter-name>struts2</filter-name>
 		<url-pattern>*.action</url-pattern>
 	</filter-mapping>
关于这个就不多说了,只要是知道struts2的应该都会了的















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值