<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/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/mvc http://www.springframework.org/schema/mvc/spring-mvc-.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.0.xsd"> <context:annotation-config /> <context:component-scan base-package="com.*" /> <!--代替hibernate.cfg.xml书写配置文件 --> <!-- <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"> --> <!-- <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> --> <!-- <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" /> --> <!-- <property name="username" value="shao" /> --> <!-- <property name="password" value="a123" /> --> <!-- </bean> --> <!--加载sessionFactory --> <!-- <bean id="sessionFactory" --> <!-- class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> --> <!-- <property name="dataSource" ref="dataSource" /> --> <!-- <property name="mappingResources"> --> <!-- <list> --> <!-- <value>cfg/Mailtb.hbm.xml</value> --> <!-- <value>cfg/Orderitem.hbm.xml</value> --> <!-- <value>cfg/Orders.hbm.xml</value> --> <!-- <value>cfg/Product.hbm.xml</value> --> <!-- <value>cfg/Productuser.hbm.xml</value> --> <!-- <value>cfg/User_product.hbm.xml</value> --> <!-- </list> --> <!-- </property> --> <!--配置属性文件即在*.properties文件中的属性 --> <!-- <property name="hibernateProperties"> --> <!-- <props> --> <!-- <prop key="show_sql">true</prop> --> <!-- <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> --> <!-- </props> --> <!-- </property> --> <!-- </bean> --> <!--AOP 切面开启事务,同时也是为了解决注解方式继承HibernateDaoSupport之后无法更新数据问题 --> <!--AOP Start(记住要导入aspectj.jar包不然会报错) --> <!-- 定义事务管理器(声明式的事务) --> <!-- <bean id="transactionManager" --> <!-- class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> --> <!-- <property name="dataSource" ref="dataSource" /> --> <!-- </bean> --> <!--对你想要增加事务的方法进行处理,这里为了笔记精简,就用*对所有方法都添加了事务 --> <!-- <tx:advice id="txAdvice" transaction-manager="transactionManager"> --> <!-- <tx:attributes> --> <!-- <tx:method name="*" propagation="REQUIRED" /> --> <!-- </tx:attributes> --> <!-- </tx:advice> --> <!--事务的含盖范围,最后要.*.*结尾,拦截该包下的所有方法 --> <!-- <aop:config> --> <!-- <aop:pointcut id="interceptorPointCuts" --> <!-- expression="execution(* com.newtouch.service.*.*(..))" /> --> <!-- <aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" /> --> <!-- </aop:config> --> <!--AOP end --> </beans>