8,906
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd" [
<!ENTITY contextInclude SYSTEM "org/springframework/web/context/WEB-INF/contextInclude.xml">
]>
<!-- 该配置用来加载数据源,设置sessionFactory,作为spring配合文件存在,是最底层,最基础的配置 。
总览hibernate等其他的配置。
-->
<beans>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:ORCL"></property>
<property name="username" value="zq"/>
<property name="password" value="zq123"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hiberante.format_sql">true</prop>
</props>
</property>
<property name="configLocations">
<list>
<value>classpath:comm/buaa/hibernate/user.cfg.xml</value>
</list>
</property>
</bean>
<!-- 代理事务处理 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 事务基类,加载bean -->
<bean id="transactionBese" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
lazy-init="true" abstract="true">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="modi*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="get*">PROPAGATION_NEVER</prop>
</props>
</property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd" [
<!ENTITY contextInclude SYSTEM "org/springframework/web/context/WEB-INF/contextInclude.xml">
]>
<beans>
<import resource="comm/buaa/xml/spring-user.xml"/>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd" [
<!ENTITY contextInclude SYSTEM "org/springframework/web/context/WEB-INF/contextInclude.xml">
]>
<beans>
<bean id="uersDao" class="comm.buaa.dao.impl.UserDao">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 为service层加载事务 -->
<bean id="userManagerBase" class="comm.buaa.service.impl.UserService">
<property name="uersDao" ref="uersDao"/>
</bean>
<!-- parent继承spring-hibernate.xml的事务id, id="userService"
指的是comm.buaa.control.UserControl的属性
-->
<bean id="userService" parent="transactionBese">
<property name="target" ref="userManagerBase"/>
</bean>
</beans>
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<mapping class="comm.buaa.bean.Users"/>
</session-factory>
</hibernate-configuration>
package comm.buaa.service.impl;
import comm.buaa.bean.Users;
import comm.buaa.dao.IUserDao;
import comm.buaa.service.IUserService;
public class UserService implements IUserService{
private IUserDao usersDao;
public void setUsersDao(IUserDao usersDao) {
this.usersDao = usersDao;
}
public IUserDao getUsersDao(){
return usersDao;
}
public void addUser(Users user) {
usersDao.addUser(user);
}
}