美文网首页
spring的配置文件

spring的配置文件

作者: 星辰无眠 | 来源:发表于2018-11-20 19:04 被阅读0次

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"

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.xsd

        http://www.springframework.org/schema/context

        http://www.springframework.org/schema/context/spring-context.xsd

        http://www.springframework.org/schema/aop

        http://www.springframework.org/schema/aop/spring-aop.xsd

        http://www.springframework.org/schema/tx

        http://www.springframework.org/schema/tx/spring-tx.xsd">

<!-- 1.加载属性文件 -->

<context:property-placeholder location="classpath:jdbc.properties"/>

<!-- 2.数据源 -->

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">

<property name="user" value="${jdbc.username}"/>

<property name="password" value="${jdbc.password}"/>

<property name="jdbcUrl" value="${jdbc.url}"/>

<property name="driverClass" value="${jdbc.driverClass}"/>

</bean>

<!-- 3.sessionFactory -->

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

<property name="dataSource" ref="dataSource"/>

<property name="configLocation" value="classpath:hibernate.cfg.xml"/>

<property name="mappingLocations" value="classpath:com/demo/entity/*.hbm.xml"/>

</bean>

<!-- 4.事务管理器 -->

<bean id="tx" class=" org.springframework.orm.hibernate3.HibernateTransactionManager">

<property name="sessionFactory" ref="sessionFactory"></property>

</bean>

<!-- 5.事务的属性 -->

<tx:advice id="txAdvices" transaction-manager="tx">

<tx:attributes>

<tx:method name="get*" isolation="DEFAULT" propagation="REQUIRED" read-only="true"/>

<tx:method name="add*" isolation="DEFAULT" propagation="REQUIRED" read-only="false"/>

<tx:method name="update*" isolation="DEFAULT" propagation="REQUIRED" read-only="false"/>

<tx:method name="delete*" isolation="DEFAULT" propagation="REQUIRED" read-only="false"/>

</tx:attributes>

</tx:advice>

<!-- 6.AOP的配置 -->

<aop:config>

<aop:advisor advice-ref="txAdvices" pointcut="execution( * com.demo.service.*.*(..))"/>

</aop:config>

<!-- 7.定义的bean -->

<bean id="demoDao" class="com.demo.dao.impl.DemoDaoImpl">

<property name="sessionFactory" ref="sessionFactory"></property>

</bean>

<bean id="demoService" class="com.demo.service.impl.DemoServiceImpl">

<property name="demoDao" ref="demoDao"></property>

</bean>

</beans>

相关文章

网友评论

      本文标题:spring的配置文件

      本文链接:https://www.haomeiwen.com/subject/kwoxqqtx.html