读书人

spring 与 hibernate Annotation配备(

发布时间: 2012-10-07 17:28:51 作者: rapoo

spring 与 hibernate Annotation配置(applicationContext.xml)

(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-ref="sessionFactory"></property>
?</bean>
?

?<bean id="dataSource"
??value="companycrm"></property>
??<property name="password" value="companycrm"></property>
?</bean>
?<!-- org.springframework.orm.hibernate3.LocalSessionFactoryBean(以前是这个,用自动扫描需要用下面的) -->
?<bean id="sessionFactory"
??/>
??</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 />
??</property>
??<!-- 才不会出现红色的叉 -->
??<property name="packagesToScan">
???<list>
????<value>com.*</value>
???</list>
??</property>
??<!--
??<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" /> -->
?</bean>
?
?<!--
?<bean id="hibernateTemplate" ref="dataSource" />
?</bean>??????????? -->
????? <!-- 支持 @AspectJ 标记??
?<aop:aspectj-autoproxy proxy-target-class="true"/>? -->
??<!-- 以AspectJ方式 定义 AOP????
?<aop:config proxy-target-class="true"></aop:config>? -->
</beans>

读书人网 >XML SOAP

热点推荐