shh结合碰到的一些想法

来源:互联网 发布:小型数据库管理系统 编辑:程序博客网 时间:2024/05/17 06:58
<?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:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/tx 
          http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/aop 
          http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context.xsd">


<!-- 公共配置项 -->
<!-- 1.1 加载properties文件 -->
<context:property-placeholder location="classpath:jdbcInfo.properties"/>

<!-- 1.2 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"></property>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>

<!-- 2. 配置SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<property name="mappingLocations" value="classpath:com/itheima/crm/*/domain/*.hbm.xml"></property>
</bean>

<!-- 3.事务管理 -->
<!-- 3.1 事务管理器 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 3.2 事务详情  
* 增删改:读写;查询:只读
-->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*"/>
<tx:method name="update*"/>
<tx:method name="delete*"/>
<tx:method name="login" read-only="true"/>
<tx:method name="find*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 3.3 aop编程  
* 强制cglib :  proxy-target-class="true"
-->
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.itheima.crm.*.service..*.*(..))"/>
</aop:config>




<!-- 4 导入其他配置文件 -->
<!-- 4.1 员工 -->
<import resource="applicationContext-staff.xml"/>

</beans>









-------------------------------

1、这边的sessionFactory是直接把Hibernate.cfg.xml的 <session-factory></session-factory>移植过来,而且还需要有个<mapping resource="com/test/Student.hbm.xml" />。今天就是没加mapping报错了。

2、Service里面的那个待注入的dao,是需要用接口来的,如果用实现类的话就找不到方法,也是今天报错的主因。

0 0
原创粉丝点击