<bean id="dataSuorces" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDirver"/>(oracle数据库)
<property name="url" value="jdbc:oracl:thin:@loaclhost:1521:orcl"/>(oracle数据库)
<property name="name" value="用户名"/>
<property name="password" value="密码"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSuorces" ref="dataSuorce"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResuoces" >
<list>
<value>com/...../User.hbm.xml</value>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
(中间省去依赖注入)
<aop:config>
<aop:advisor advice-ref="transactionAdvice" pointcut="execution(* com.foreveross.ssh.service.UserService.*(..))"/>
</aop:config>
</beans>
为了方便理解去搭建SSH一下是我搭建框架的思路,请大家多多指教--------------------------------:
配置hibernate的sessionFactory
里面有属性:dataSuorce 连接数据源ref(在前面配置数据连接源)
取得数据源后和数据库打交道的方式属性:hibernateProperties:prop:里面用Map存键值<prop key="">value</prop>
key=hibernate.dialect:数据库类型(value)
hibernate.hbm2ddl.auto:自动生成DDL的方式
hibernate.show_sql:是否展示sql语句
hibernate.format_sql是否用数据库规定的方式
mappingResuorces:映射文件的读取:装list里面,value=项目下的映射文件路径<list><value>com/foreveross/ssh/entity/User.hbm.xml</value></list>
配置切入表达式<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
配置切入点<aop:config>
<aop:advisor advice-ref="transactionAdvice" pointcut="execution(* com.foreveross.ssh.service.UserService.*(..))"/>
</aop:config>