applicationContext.xml的配置文件
2010-06-03 20:00
435 查看
<?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: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-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 基于annotation的配置 -->
<context:annotation-config />
<!-- 扫描所属项目的包 -->
<context:component-scan base-package="auction"/>
<!-- 数据库配置 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test" />
<property name="username" value="root" />
<property name="password" value="11011" />
<!--
<property name="maxPoolSize" value="40" />
<property name="minPoolSize" value="1" />
<property name="initialPoolSize" value="1" />
<property name="maxIdleTime" value="20"/>
-->
</bean>
<!-- 定义hibernate的sessionfactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<!-- 映射文件 -->
<list>
<value>com.auction.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>
<!-- 使用hibernatetemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config>
<!-- 配置一个切入点,匹配com.spring.main.dao包下所有以dao结尾的类的所有方法的执行 -->
<aop:pointcut expression="execution(public * com.spring.mail.dao.*.*(..))" id="bussinessService"/>
<aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice"/>
</aop:config>
<!-- 配置事务切面bean,指定事务管理器 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<!-- 用于配置详细的事务语义 -->
<tx:attributes>
<tx:method name="get*" read-only="true" /> <!-- 所有以get开头的方法 -->
<tx:method name="save"/>
<tx:method name="*" />
</tx:attributes>
</tx:advice>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 基于annotation的配置 -->
<context:annotation-config />
<!-- 扫描所属项目的包 -->
<context:component-scan base-package="auction"/>
<!-- 数据库配置 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test" />
<property name="username" value="root" />
<property name="password" value="11011" />
<!--
<property name="maxPoolSize" value="40" />
<property name="minPoolSize" value="1" />
<property name="initialPoolSize" value="1" />
<property name="maxIdleTime" value="20"/>
-->
</bean>
<!-- 定义hibernate的sessionfactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<!-- 映射文件 -->
<list>
<value>com.auction.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>
<!-- 使用hibernatetemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config>
<!-- 配置一个切入点,匹配com.spring.main.dao包下所有以dao结尾的类的所有方法的执行 -->
<aop:pointcut expression="execution(public * com.spring.mail.dao.*.*(..))" id="bussinessService"/>
<aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice"/>
</aop:config>
<!-- 配置事务切面bean,指定事务管理器 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<!-- 用于配置详细的事务语义 -->
<tx:attributes>
<tx:method name="get*" read-only="true" /> <!-- 所有以get开头的方法 -->
<tx:method name="save"/>
<tx:method name="*" />
</tx:attributes>
</tx:advice>
</beans>
相关文章推荐
- 服务器运行的状态,修改Spring中的applicationContext.xml配置文件
- 【引用】ssh配置文件(web.xml,struts.xml,applicationContext.xml,persistence.xml,log4j.properties)
- spring applicationContext.xml 配置文件 详解
- Spring Data JPA applicationContext.xml 配置文件报错的解决办法
- JAVA配置文件之applicationContext.xml
- 一个典型的Spring的applicationcontext.xml配置文件
- 【Spring】如何配置多个applicationContext.xml文件
- applicationContext.xml 配置文件的存放位置
- hibernate3使用注解,spring配置文件applicationContext.xml的配置
- 要想看懂 spring 的配置文件:ApplicationContext.xml 第一步
- Spring配置文件详解 - applicationContext.xml文件路径
- Spring的主配置文件applicationContext.xml
- spring applicationContext.xml 配置文件 详解
- Spring的配置文件applicationContext.xml
- 读取applicationContext.xml(spring配置文件)文件
- Spring基础学习教程(applicationContext.xml 配置文件 详解)-07
- SSM整合之applicationContext.XML配置文件详解
- applicationContext.xml import spring模块配置文件
- SpringAOP配置文件applicationContext.xml
- Spring MVC框架下在java代码中访问applicationContext.xml文件中配置的文件(可以用于读取配置文件内容)