Hibernate + Spring配置
Hibernate + Spring配置
<!-- 第一步:配置数据源 -->
<bean id="dateSource" value="java:comp/env/jdbc/oracle">
</property>
</bean>
<!-- 第一步:配置数据源 -->
<bean id="propertyConfigurer" destroy-method="close">
<property name="driverClassName" value="${source.driverClassName}" />
<property name="url" value="${source.url}" />
<property name="username" value="${source.username}" />
<property name="password" value="${source.password}" />
<property name="initialSize" value="4" />
<property name="maxActive" value="20" />
<property name="testWhileIdle" value="true" />
<property name="validationQuery" value="select 1 from dual" />
<property name="testOnBorrow" value="true" />
</bean>
<!-- 第二步:配置sessionFactory -->
<!-- 配置大字段 -->
<bean id ="nativeJdbcExtractor" class ="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor" lazy-init ="true" />
<bean id ="oracleLobHandler" class ="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init ="true" >
<property name ="nativeJdbcExtractor" ref ="nativeJdbcExtractor" />
</bean>
<bean id="sessionFactory"
/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<!-- ==============基础模块====================== -->
<!-- 单位BEAN -->
<value>com/nsoft/bean/BaseUnit.hbm.xml</value>
<!-- 部门BEAN -->
<value>com/nsoft/bean/BaseDept.hbm.xml</value>
</list>
<property>
<property name="lobHandler">
<ref local="oracleLobHandler"/>
</property>
</bean>
<!-- 第三步:配置事务管理器 -->
<bean name="transactionManager" ref="sessionFactory">
</property>
</bean>
<!-- 第四步:配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="set*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="import*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!--第五步:配置哪些类的哪些方法使用事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.nsoft.service.*.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
</aop:config>
<!-- 第六步:配置action对象 -->
<bean id="lwxtPublicDao" />
</property>
</bean>
<bean id="lwxtPublicAction" scope="prototype">
<property name="lwxtPublicService">
<ref bean="lwxtPublicService" />
</property>
</bean>
<bean id="lwxtPublicService" />
</property>
<property name="lwxtPublicDao">
<ref bean="lwxtPublicDao" />
</property>
<property name="baseSpecDao">
<ref bean="baseSpecDao" />
</property>
</bean>
1 楼 rskyz520 2010-03-09 很基础。很实用。谢谢。