(3) applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byName" default-lazy-init="false"
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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<context:annotation-config/>
<!-- 使用annotation 自动注册bean ,并检查@Required,@Autowired的属性已被注入 -->
<context:component-scan base-package="com">
<!--
<context:exclude-filter type="regex" expression=".*Service$"/>
<context:exclude-filter type="regex" expression="com.service.*"/>-->
</context:component-scan>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<!-- 事务配置 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@192.168.1.253:1521:orcl">
</property>
<property name="username" value="companycrm"></property>
<property name="password" value="companycrm"></property>
</bean>
<!-- org.springframework.orm.hibernate3.LocalSessionFactoryBean(以前是这个,用自动扫描需要用下面的) -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<!--<prop key="hibernate.current_session_context_class">thread</prop> 使用SessionFactory.getCurrentSession()需要在hibernate.cfg.xml中如下配置 -->
</props>
</property>
<property name="namingStrategy">
<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
</property>
<!-- class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" 才不会出现红色的叉 -->
<property name="packagesToScan">
<list>
<value>com.*</value>
</list>
</property>
<!--
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" /> -->
</bean>
<!--
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
-->
<!--
<bean id="transactionManager2" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean> -->
<!-- 支持 @AspectJ 标记
<aop:aspectj-autoproxy proxy-target-class="true"/> -->
<!-- 以AspectJ方式 定义 AOP
<aop:config proxy-target-class="true"></aop:config> -->
</beans>