spring,springmvc 在web.xml中的配置以及applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
         version="2.5"><
  <!-- Spring配置文件开始  -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:com/avicit/resource/spring/spring-base.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- Spring配置文件结束 -->

  <!--配置springmvc-->
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <!--servlet-class中的值是spring-webmvc包提供的类,即前端控制器,用于控制所有请求 -->
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring/springmvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <!--url-pattern(重点)中有3个值,分别为/、 /*、 *.action  -->
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  
  <filter>
    <filter-name>encoding</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>
  </filter>
  <filter-mapping>
    <filter-name>encoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

</web-app>

对于

org.springframework.web.context.ContextLoaderListener
可以参见
http://blog.csdn.net/seng3018/article/details/6758860 中的说明

一般spring上下文中xml默认叫applicationContext.xml
···

<context:component-scan base-package="com.avicit">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
        	<value>classpath*:com/avicit/resource/jdbc/jdbc.properties</value>
        	<value>classpath*:com/avicit/resource/hibernate/hibernate.properties</value>
        </list>
    </property>
</bean>


<!-- 国际化的消息资源文件 -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <!-- 在web环境中一定要定位到classpath 否则默认到当前web应用下找  -->
            <value>classpath:com/avicit/resource/message/messages</value>
        </list>
    </property>
    <property name="defaultEncoding" value="UTF-8"/>
    <property name="cacheSeconds" value="60"/>
</bean>

<import resource="classpath*:com/avicit/resource/spring/spring-dao.xml"/>
  <import resource="classpath*:com/avicit/resource/spring/spring-dao.xml"/>
这里导入了另一个配置文件,就是配置数据源的
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=“http://www.springframework.org/schema/beans”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:p=“http://www.springframework.org/schema/p”
xmlns:context=“http://www.springframework.org/schema/context”
xmlns:aop=“http://www.springframework.org/schema/aop” xmlns:tx=“http://www.springframework.org/schema/tx”

xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">


<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
	<property name="alias" value="proxoolDataSource" />
	<property name="driver" value="${jdbc.driver}" />
	<property name="driverUrl" value="${jdbc.url}" />
	<property name="user" value="${jdbc.username}" />
	<property name="password" value="${jdbc.password}" />
	<property name="maximumConnectionCount" value="${jdbc.maximum.connection.count}" />
	<property name="minimumConnectionCount" value="${jdbc.minimum.connection.count}" />
	<property name="statistics" value="${jdbc.statistics}" />
	<property name="simultaneousBuildThrottle" value="${jdbc.simultaneous.build.throttle}" />
</bean>


<bean id="sessionFactory"
	class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
	<property name="dataSource" ref="dataSource" />
	<property name="packagesToScan" value="com.avicit" />
	<property name="hibernateProperties">
		<props>
			<prop key="hibernate.dialect">${hibernate.dialect}</prop>
			<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
			<prop key="hibernate.format_sql">true</prop>
			<prop key="hibernate.query.substitutions">${hibernate.query.substitutions}</prop>
			<prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
			<prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
			<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
			<prop key="hibernate.bytecode.use_reflection_optimizer">${hibernate.bytecode.use_reflection_optimizer}</prop>


			<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
			<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
			<prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
			<prop key="net.sf.ehcache.configurationResourceName">${net.sf.ehcache.configurationResourceName}</prop>
			<prop key="hibernate.cache.use_structured_entries">${hibernate.cache.use_structured_entries}</prop>
		</props>
	</property>
</bean>


<bean id="lookupResolver"
	class="com.avicit.framework.support.matchrule.context.HibernateMatchRuleResolver">
	<property name="packagesToScan" value="com.avicit.fes.*" />
</bean>


<!-- 开启AOP监听 只对当前配置文件有效 -->
<aop:aspectj-autoproxy expose-proxy="true" />


<!-- 开启注解事务 只对当前配置文件有效 -->
<tx:annotation-driven transaction-manager="txManager" />


<bean id="txManager"
	class="org.springframework.orm.hibernate4.HibernateTransactionManager">
	<property name="sessionFactory" ref="sessionFactory" />
</bean>


<tx:advice id="txAdvice" transaction-manager="txManager">
	<tx:attributes>
		<tx:method name="save*" propagation="REQUIRED" />
		<tx:method name="add*" propagation="REQUIRED" />
		<tx:method name="create*" propagation="REQUIRED" />
		<tx:method name="insert*" propagation="REQUIRED" />
		<tx:method name="update*" propagation="REQUIRED" />
		<tx:method name="merge*" propagation="REQUIRED" />
		<tx:method name="del*" propagation="REQUIRED" />
		<tx:method name="remove*" propagation="REQUIRED" />
		<tx:method name="put*" propagation="REQUIRED" />
		<tx:method name="use*" propagation="REQUIRED" />
		<!--hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到 -->
		<tx:method name="get*" propagation="REQUIRED" read-only="true" />
		<tx:method name="count*" propagation="REQUIRED" read-only="true" />
		<tx:method name="find*" propagation="REQUIRED" read-only="true" />
		<tx:method name="list*" propagation="REQUIRED" read-only="true" />
		<tx:method name="*" read-only="true" />
	</tx:attributes>
</tx:advice>
<aop:config expose-proxy="true">
	<!-- 只对业务逻辑层实施事务 -->
	<aop:pointcut id="txPointcut"
		expression="execution(* com.avicit..service..*.*(..))" />
	<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" />
</aop:config>
```
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值