Spring事务管理配置

2014-11-24 03:02:54 · 作者: · 浏览: 0

刚学习SSH架构,迫不及待做了个例子,心情难免激动,晒出来,大家分享一下。

一、数据库连接文件:dbConfig.cfg.xml

< xml version='1.0' encoding='UTF-8' >

"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

com.microsoft.jdbc.sqlserver.SQLServerDriver

jdbc:microsoft:sqlserver://127.0.0.1:1433

NewOA

sa

hjl

org.hibernate.dialect.SQLServerDialect

true

二、Spring配置文件:enginConfig.xml

< xml version="1.0" encoding="UTF-8" >

xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

value="classpath:dbConfig.cfg.xml">

class="org.springframework.orm.hibernate3.HibernateTransactionManager">

class="org.springframework.transaction.interceptor.TransactionInterceptor">

PROPAGATION_REQUIRED

PROPAGATION_REQUIRED

PROPAGATION_REQUIRED

PROPAGATION_REQUIRED,+MyMsgException

PROPAGATION_REQUIRED,-MyErrException

PROPAGATION_REQUIRED,readOnly

class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">

oatWfFlowmapTypeService

transactionInterceptor

class="com.myEngin.wfmap.daoImpl.OatWfFlowmapTypeDaoImpl">

class="com.myEngin.wfmap.serviceImpl.OatWfFlowmapTypeServiceImpl">

三、OatWfFlowmapTypeDaoImpl.java文件:

public class OatWfFlowmapTypeDaoImpl extends HibernateDaoSupport implements

OatWfFlowmapTypeDao {。。。。略}

四、OatWfFlowmapTypeServiceImpl.java文件:

public class OatWfFlowmapTypeServiceImpl implements OatWfFlowmapTypeService {

//private OatWfFlowmapTypeDao flowmaptypedao;

private OatWfFlowmapTypeDao oatWfFlowmapTypeDao;

public OatWfFlowmapTypeDao getOatWfFlowmapTypeDao() {

return oatWfFlowmapTypeDao;

}

public void setOatWfFlowmapTypeDao(OatWfFlowmapTypeDao oatWfFlowmapTypeDao) {

this.oatWfFlowmapTypeDao = oatWfFlowmapTypeDao;

}

。。。。。略

}

五、测试文件test.java:

public static void main(String[] args) {

OatWfFlowmapType map=new OatWfFlowmapType();

map.setFId(44);

map.setFName("ccccc");

map.setFDesc("44444");

map.setFCreateUserId(4);

Date dt=new Date();

SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String mydt=f.format(dt);

map.setFCreateDateTime(Timestamp.valueOf("2010-06-02 10:20:30"));

map.setFLastEditUserId(444);

map.setFLastEditDateTime(Timestamp.valueOf(mydt));

map.setFSort(4);

map.setFState(Short.decode("1"));

ApplicationContext ctx=new ClassPathXmlApplicationContext("enginConfig.xml")

OatWfFlowmapTypeService service=(OatWfFlowmapTypeService)ctx.getBean("oatWfFlowmapTypeService");

service.save(map);

}

完。

摘自:huangjl2000w的专栏