spring 基于注解的 配置
现有项目是 在 eclipse 中 ,
已实现了 spring mvc 注解的配置 ,,
数据方面是 jdbc
现我想加入 jpa 用hibernater
如何配置呢 ,?
<?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:p="http://www.springframework.org/schema/p"
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-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">
<context:annotation-config />
<aop:aspectj-autoproxy />
<bean id="placeholderConfig" class="com.yht.ipcentrex.filter.SystemPropertiesLoader">
</bean>
<bean id="dataSource" class="org.postgresql.jdbc3.Jdbc3PoolingDataSource"
scope="singleton">
<property name="dataSourceName" value="${db.dataSourceName}" />
<property name="serverName" value="192.168.1.105" />
<property name="databaseName" value="${db.databaseName}" />
<property name="user" value="${db.user}" />
<property name="password" value="${db.password}" />
<property name="portNumber" value="${db.portNumber}" />
<property name="maxConnections" value="${db.maxConnections}" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>com/yht/ipcentrex/i18n/message
</value>
<value>com/yht/ipcentrex/i18n/adminViews
</value>
<value>com/yht/ipcentrex/i18n/resellerViews
</value>
<value>com/yht/ipcentrex/i18n/accountViews
</value>
<value>com/yht/ipcentrex/i18n/agentViews
</value>
<value>com/yht/ipcentrex/i18n/utilViews
</value>
</list>
</property>
</bean>
<bean id="abstractDao" class="com.yht.ipcentrex.dao.AbstractDao"
abstract="true">
<property name="jdbcTemplate">
<ref bean="jdbcTemplate" />
</property>
</bean>
<!-- <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">-->
<!-- <property name="dataSource" ref="dataSource"/>-->
<!-- </bean>-->
<!--conifg active mq-->
<bean id="connectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="${mq.host}" />
</bean>
</property>
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" scope="prototype">
<property name="connectionFactory" ref="connectionFactory" />
</bean>
<!-- send mail -->
<bean id="emailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl" scope="prototype">
<property name="host" value="${mail.host}"/>
<property name="port" value="465"/>
<property name="username" value="${mail.userName}" />
<property name="password" value="${mail.password}"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
</props>
</property>
</bean>
<!-- time scheduler-->
<bean id="jobBean" class="com.yht.ipcentrex.time.Job" />
<bean name="exampleJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.yht.ipcentrex.time.ExampleJob" />
<property name="jobDataAsMap">
<map>
<entry key="timeout" value="5" />
</map>
</property>
</bean>
<bean id="job"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="jobBean" />
<property name="targetMethod" value="execute" />
<property name="concurrent" value="false" />
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="exampleJob" />
<property name="cronExpression" value="0 48 10 * * ?" />
</bean>
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="job" />
<property name="startDelay" value="10000" />
<property name="repeatInterval" value="10000" />
</bean>
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" autowire="default" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="provider">org.hibernate.ejb.HibernatePersistence</prop>
</props>
</property>
<property name="loadTimeWeaver" >
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />
</beans>
spring-servlet.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:p="http://www.springframework.org/schema/p"
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-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">
<context:annotation-config />
<context:component-scan base-package="com.yht.ipcentrex.*" />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean name="viewResolver1"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:suffix=".jsp" />
<!--
<bean id="beanNameViewResolver"
class="org.springframework.web.servlet.view.BeanNameViewResolver">
<property name="order" value="1" /> </bean>
-->
<bean name="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
<property name="order" value="1" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger" />
<ref bean="simpleTrigger" />
</list>
</property>
</bean>
<bean id="themeSource"
class="org.springframework.ui.context.support.ResourceBundleThemeSource">
<property name="basenamePrefix" value="themes/" />
</bean>
<bean id="themeResolver"
class="org.springframework.web.servlet.theme.SessionThemeResolver">
<property name="defaultThemeName">
<value>yellow</value>
</property>
</bean>
<aop:config>
<aop:aspect id="controlAspect" ref="controlAspectBean">
<!--配置com.spring.service包下所有类或接口的所有方法-->
<aop:pointcut id="businessService" expression="execution(* com.yht.ipcentrex.control..*.*(..))" />
<aop:before pointcut-ref="businessService" method="doBefore"/>
<aop:after pointcut-ref="businessService" method="doAfter"/>
<aop:around pointcut-ref="businessService" method="doAround"/>
<aop:after-throwing pointcut-ref="businessService" method="doThrowing" throwing="ex"/>
</aop:aspect>
</aop:config>
<!--
<aop:config>
<aop:aspect id="jdbcAspect" ref="jdbcAspectBean">
<aop:pointcut id="jdbcDao" expression="execution(* com.yht.ipcentrex.dao..*.*(..))" />
<aop:after pointcut-ref="jdbcDao" method="doAfter"/>
</aop:aspect>
</aop:config>
-->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" rollback-for="Exception"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="serviceOperation" expression="execution(* com.yht.ipcentrex.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation"/>
</aop:config>
</beans>