配置文件
spring的,其中hibernate.cfg.xml能用,只用hibernate测试没问题,所以那个文件不贴了
<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- 声明事物,做用就是对一系列操作在运行时错误的情况能回滚 -->
<!-- 事物管理 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 事物拦截器 -->
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<!-- 下面定义事物传播属性 -->
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- 业务实例动态代理 -->
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<!-- 下面是所有要创建代理事物的bean -->
<list>
<value>service</value>
</list>
</property>
<!-- 下面定义 所需的事物拦截器 -->
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<!-- 业务逻辑的bean -->
<bean id="service" class="com.lp.logic.impl.ServiceImpl">
<property name="loginDao">
<ref bean="loginDao"/>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
<property name="allowCreate">
<value>true</value>
</property>
</bean>
<bean id="loginDao" class="com.lp.dao.impl.LoginDaoImpl">
<property name="hibernateTemplate" ref="hibernateTemplate" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="baseAction" class="com.lp.action.base.BaseAction" scope="prototype">
<property name="ser" ref="service" />
</bean>
</beans>
spring的,其中hibernate.cfg.xml能用,只用hibernate测试没问题,所以那个文件不贴了
<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- 声明事物,做用就是对一系列操作在运行时错误的情况能回滚 -->
<!-- 事物管理 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 事物拦截器 -->
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<!-- 下面定义事物传播属性 -->
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- 业务实例动态代理 -->
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<!-- 下面是所有要创建代理事物的bean -->
<list>
<value>service</value>
</list>
</property>
<!-- 下面定义 所需的事物拦截器 -->
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<!-- 业务逻辑的bean -->
<bean id="service" class="com.lp.logic.impl.ServiceImpl">
<property name="loginDao">
<ref bean="loginDao"/>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
<property name="allowCreate">
<value>true</value>
</property>
</bean>
<bean id="loginDao" class="com.lp.dao.impl.LoginDaoImpl">
<property name="hibernateTemplate" ref="hibernateTemplate" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="baseAction" class="com.lp.action.base.BaseAction" scope="prototype">
<property name="ser" ref="service" />
</bean>
</beans>
解决方案 »
- 你们说使用SSH到底是为了快速开发,还是为了标准?
- SSH中调用Hibernate的Session问题,急啊!!!
- 我间隔5秒执行KILL -3 〈JAVA PID〉命令3次,却只生成了一个JAVACORE文件,请问怎样生成多个?
- html转换成xml和xsl后打用浏览器开页面为什么变了
- SQL Server 2005 Driver for jdbc 连接数据库时出现异常,不知怎么办?请各位大侠给于帮助!十分感谢!
- j2ee学习流程
- html转xml
- 怎么在resin中创建虚拟目录?
- 一道面试题, 大家看看怎么答啊!
- 一个菜鸟问题
- Java EE与数据库学习顺序与问题求助~~~~
- 等待框的问题
里面用getHibernateTemplate()方法操作吧,但是那个方法就返回null,所以我就获取了一下SessionFactory,结果也是null
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>