spring2.5+hibernate配置文件事务管理的写法 如题所述,想要一个spring2.5+hibernate配置文件的最新写法参考下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 网上有spring2.5的文档,你去下一个,里面写的很清楚的, 配置数据源<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/spring?useUnicode=true&characterEncoding=utf8"/> <property name="username" value="root"/> <property name="password" value="123456"/> <property name="maxActive" value="100"/> <property name="maxIdle" value="30"/> <property name="maxWait" value="1000"/> <property name="defaultAutoCommit" value="true"/> <property name="removeAbandoned" value="true"/> <property name="removeAbandonedTimeout" value="60"/> <property name="logAbandoned" value="true"/> </bean><!-- 配置hibernate的SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!-- 依赖注入SessionFactory所需要的DataSource --> <property name="dataSource" ref="dataSource"/> <!-- 加载所有的映射文件 --> <property name="mappingResources"> <!-- 下面列出所有的持久化映射文件 --> <list> <value>web/model/news/News.hbm.xml</value> <value>web/model/news/User.hbm.xml</value> <value>web/model/news/Review.hbm.xml</value> <value>web/model/news/Poster.hbm.xml</value> <value>web/model/news/Category.hbm.xml</value> </list> </property> <!-- 指定hibernate的属性 --> <property name="hibernateProperties"> <props> <!-- 指定hibernate使用的数据库方言 org.hibernate.dialect.MySQLDialect--> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean>以下是配置事务<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <!-- the transactional semantics... --> <tx:attributes> <!-- all methods starting with 'get' are read-only --> <tx:method name="get*" read-only="true"/> <tx:method name="load*" read-only="true"/> <tx:method name="list*" read-only="true"/> <!-- other methods use the default transaction settings (see below) --> <tx:method name="*"/> </tx:attributes> </tx:advice> <!-- ensure that the above transactional advice runs for any execution of an operation defined by the FooService interface com.dtb.web.impl--> <aop:config> <aop:pointcut id="webServiceOperation" expression="execution(这里是事务的目录)"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="webServiceOperation"/> </aop:config> 如果不用AOP控制的话。。应该怎么写呢? 使用注解<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${driverClassName}" /> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> <property name="initialSize" value="${initialSize}" /> <property name="maxActive" value="${maxActive}" /> <property name="maxIdle" value="${maxIdle}" /> <property name="minIdle" value="${minIdle}" /> <property name="maxWait" value="${maxWait}" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mappingResources"> <list> <value>cn/itcast/domain/Person.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.hbm2ddl.auto=update hibernate.show_sql=true hibernate.format_sql=true </value> </property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:annotation-driven transaction-manager="txManager" /> 64位的Weblogic10.2在myeclipse中无法正常启动(100分求助) Web高级开发工程师(>8K) struts验证框架的问题 前台js怎么判断action执行完毕,并执行下面的代码 SSH配置中出现空指针 请大牛帮看看 想找hibernate_reference这本书里的例子下载的网址? SSO 开源之选择 关于LOG4J生成以时间命名的log文件的问题 javabean调用ejb,jsp调用javabean.出现了如下问题,需要高手出现啊! hibernate struts的tiles问题 SSH2,后台调用Dao为空的问题
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/spring?useUnicode=true&characterEncoding=utf8"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
<property name="maxActive" value="100"/>
<property name="maxIdle" value="30"/>
<property name="maxWait" value="1000"/>
<property name="defaultAutoCommit" value="true"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="60"/>
<property name="logAbandoned" value="true"/>
</bean><!-- 配置hibernate的SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 依赖注入SessionFactory所需要的DataSource -->
<property name="dataSource" ref="dataSource"/>
<!-- 加载所有的映射文件 -->
<property name="mappingResources">
<!-- 下面列出所有的持久化映射文件 -->
<list>
<value>web/model/news/News.hbm.xml</value>
<value>web/model/news/User.hbm.xml</value>
<value>web/model/news/Review.hbm.xml</value>
<value>web/model/news/Poster.hbm.xml</value>
<value>web/model/news/Category.hbm.xml</value>
</list>
</property>
<!-- 指定hibernate的属性 -->
<property name="hibernateProperties">
<props>
<!-- 指定hibernate使用的数据库方言 org.hibernate.dialect.MySQLDialect-->
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>以下是配置事务
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean> <tx:advice id="txAdvice" transaction-manager="txManager">
<!-- the transactional semantics... -->
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true"/>
<tx:method name="load*" read-only="true"/>
<tx:method name="list*" read-only="true"/>
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="*"/>
</tx:attributes>
</tx:advice> <!-- ensure that the above transactional advice runs for any execution
of an operation defined by the FooService interface com.dtb.web.impl-->
<aop:config>
<aop:pointcut id="webServiceOperation" expression="execution(这里是事务的目录)"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="webServiceOperation"/>
</aop:config>
如果不用AOP控制的话。。应该怎么写呢?
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driverClassName}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="${initialSize}" />
<property name="maxActive" value="${maxActive}" />
<property name="maxIdle" value="${maxIdle}" />
<property name="minIdle" value="${minIdle}" />
<property name="maxWait" value="${maxWait}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>cn/itcast/domain/Person.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.format_sql=true
</value>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />