Spring配置文件总结
Spring配置文件总结(转)
2010-06-07 23:51:02| 分类: Spring | 标签:property value class |字号 订阅 首先来看一个标准的Spring配置文件 applicationContext.xml
com.mysql.jdbc.Driver jdbc:mysql://localhost/ssh?characterEncoding=utf-8 root 123
com/ssh/pojo/User.hbm.xml true
//////////////////////////////////////////////// 下面是详解: ////////////////////////////////////////////////////////////////////////
1.基本配置:
<context:component-scan base-package="com.persia">
</context:component-scan>
context:annotation-config
</context:annotation-config>
2.开启AOP:
aop:aspectj-autoproxy</aop:aspectj-autoproxy> AOP的xml版本
aop:aspectj-autoproxy</aop:aspectj-autoproxy>
aop:config
<aop:aspect id="myaop" ref="aspectBean">
<aop:pointcut id="mycut" expression="execution(* com.persia.service.impl.PersonServiceImpl.(..))"/>
<aop:pointcut id="argcut" expression="execution( com.persia.service.impl.PersonServiceImpl.*(..)) and args(name)"/>
<aop:before pointcut-ref="mycut" method="doAccessCheck" />
<aop:after-returning pointcut-ref="mycut" method="doAfterReturning"/>
<aop:after-throwing pointcut-ref="mycut" method="doThrowing"/>
<aop:after pointcut-ref="argcut" method="doAfter" arg-names="name"/>
<aop:around pointcut-ref="mycut" method="arround"/>
</aop:aspect>
</aop:config>
3.开启事务和注解:
aop:aspectj-autoproxy</aop:aspectj-autoproxy>
<tx:annotation-driven transaction-manager="txManager"/>
XML版本:
aop:aspectj-autoproxy</aop:aspectj-autoproxy>
<!-- 使用XML来使用事务管理-->
aop:config
<aop:pointcut id="transactionPointcut" expression="execution(* com.persia.service...(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="transactionPointcut"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
tx:attributes
<tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
4.SSH:
<!-- 1.首先在sessionFactory里面配置以上3条设置 -->
<!-- 2.然后得在类路径下面添加一个ehcache.xml的缓存配置文件 -->
<!-- 3.最后在要使用缓存的实体bean的映射文件里面配置缓存设置 -->
<!--使用二级缓存-->
<!-- 不使用查询缓存,因为命中率不是很高 -->
<!-- 使用Ehcache缓存产品 -->
<tx:annotation-driven transaction-manager="txManager"/>
context:annotation-config</context:annotation-config>
5.SSH2:
<!-- 1.首先在sessionFactory里面配置以上3条设置 -->
<!-- 2.然后得在类路径下面添加一个ehcache.xml的缓存配置文件 -->
<!-- 3.最后在要使用缓存的实体bean的映射文件里面配置缓存设置 -->
<!--使用二级缓存-->
<!-- 不使用查询缓存,因为命中率不是很高 -->
<!-- 使用Ehcache缓存产品 -->
<tx:annotation-driven transaction-manager="txManager"/>
context:annotation-config</context:annotation-config>
6.SSJ:
context:annotation-config</context:annotation-config>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
<tx:annotation-driven transaction-manager="txManager"/>