beans.xml
- XML code
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <context:annotation-config></context:annotation-config> <context:component-scan base-package="com.chk"></context:component-scan> <!-- 使用annotation管理 Transaction 事务管理 --> <!-- <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven> --> <!-- 使用XML方法管理Transaction事务 --> <!-- <bean name="userService" class="com.chk.service.UserService"></bean> --> <!-- <aop:aspectj-autoproxy></aop:aspectj-autoproxy> --> <!-- <bean id="logInterceptor" class="com.chk.aop.LogInterceptor"></bean> <aop:config> <aop:pointcut expression="execution(public * com.chk.impl..*(..))" id="servicePointcut" /> <aop:aspect id="logAspect" ref="logInterceptor"> <aop:before method="beforMothed" pointcut-ref="servicePointcut" /> </aop:aspect> </aop:config> --> <!-- 配置数据库连接 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!-- results in a setDriverClassName(String) call --> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/oa" /> <property name="username" value="root" /> <property name="password" value="chengke168" /> </bean> <!-- 产生sessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <!-- 连接数据库 --> <property name="dataSource" ref="dataSource" /> <property name="annotatedClasses"> <list> <value>com.chk.model.Orgnization</value> <value>com.chk.model.Person</value> </list> </property> <!-- <property name="packagesToScan"> <list> <value>com.chk.model</value> </list> </property> --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">create</prop> </props> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <aop:config> <aop:pointcut expression="execution(public * com.chk.service..*(..))" id="buessinessService" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="buessinessService" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" read-only="true" /> <tx:method name="add*" /> </tx:attributes> </tx:advice> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- <bean id="orgManager" class="com.chk.service.impl.OrgManagerImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> --></beans>