SSH整合中applicationContext.xml配置文件
有两种写法:
<?xml version="1.0" encoding="UTF-8"?>
<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:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
<!-- 1.直接配置Hibernate和数据库的配置
配置数据源
<bean id="ds"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
配置连接参数
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
<property name="driverClass" value="oracle.jdbc.OracleDriver" />
<property name="user" value="scott"/>
<property name="password" value="tiger"/>
配置连接池
<property name="initialPoolSize" value="3" />
<property name="maxPoolSize" value="10"/>
<property name="minPoolSize" value="1" />
<property name="acquireIncrement" value="3"/>
<property name="maxIdleTime" value="60"></property>
</bean>
配置SessionFactory
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
依赖数据源
<property name="dataSource" ref="ds"/>
Hibernate 框架相关配置
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.formate_sql">true</prop>
</props>
</property>
加载实体类的映射文件位置及名称
<property name="mappingResources">
<list>
<value>com/student/entity/student.hbm.xml</value>
<value>com/user/entity/user.hbm.xml</value>
</list>
</property>
</bean>-->
<!-- 2.Hibernate和数据库的配置写在hibernate.cfg.xml中,引入文件 -->
<!-- 配置数据源 -->
<bean id="ds"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
</bean>
<!-- 配置SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 依赖数据源 -->
<property name="dataSource" ref="ds"/>
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean>
<!-- 配置Dao -->
<bean id="EmpDao" class="com.lkl.dao.EmpDaoImpl">
<!--hibernate3下必须使用spring提供的HibernateTemplate模板类来代替Session操作数据,注入hibernateTemplate -->
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean>
<!-- 配置HibernateTemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<!-- 注入sessionFactory -->
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 配置业务实例Service -->
<bean id="EmpService" class="com.lkl.EmpServiceImpl" scope="prototype">
<property name="EmpDao" ref="EmpDao"></property>
</bean>
<!-- 配置Action -->
<bean id="EmpAction" class="com.lkl.action.EmpAction">
<property name="EmpService" ref="EmpService"></property>
</bean>
<!-- 开启注解扫描 -->
<context:component-scan base-package="com.lkl" />
<!-- 声明式事务管理,采用AOP形式切入 -->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="load*" read-only="true"/>
<tx:method name="execute" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:advisor advice-ref="txAdvice"
pointcut="within(com.lkl.action.*)" />
</aop:config>
</beans>
其中hibernate.cfg.xml的具体参数请查看我的博文
http://blog.csdn.net/qq_30938705/article/details/79290432