spring+annotation+hibernate自动建表

<?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-3.0.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-3.0.xsd">

         <context:component-scan base-package="org.itec.elwg" />
         <bean id="propertyConfiger" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
             <property name="location">
                 <value>classpath:configuration.properties</value>
             </property>
         </bean>
         <!-- 配置数据源 -->
         <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
             <property name="driverClassName" value="${jdbc.driverClassName}" />
             <property name="url" value="${jdbc.url}" />
             <property name="username" value="${jdbc.username}" />
             <property name="password" value="${jdbc.password}" />
</bean>

<!-- 配置数据源事务管理器 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
             <property name="dataSource">
                 <ref bean="dataSource" />
            </property>
            <property name="sessionFactory">
                <ref bean="sessionFactory" />
            </property>
         </bean>
         <!-- 配置sessionFactory -->
         <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
             <property name="dataSource">
                 <ref bean="dataSource" />
             </property>
             <property name="hibernateProperties">
                 <props>
         [color=red] <prop key="hibernate.hbm2ddl.auto">create</prop> [/color]            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                     <prop key="hibernate.show_sql">true</prop>
                     <prop key="hibernate.format_sql">true</prop>
                 </props>
             </property>
             <!-- 实体类 -->
             <property name="packagesToScan">
                 <list>
                     <value>org.my.entity</value>
                 </list>
             </property>
          </bean>

         <!-- 配置HibernateTemplate -->
         <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
             <property name="sessionFactory">
                 <ref bean="sessionFactory" />
             </property>
         </bean>
   
    <!-- 事务通知 -->
    <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
            <tx:method name="add*" propagation="REQUIRED" />
        </tx:attributes>
    </tx:advice>
   
    <!-- Spring AOP config -->
    <aop:config>
        <!-- 切入点 -->
        <aop:pointcut id="servicePointcut" expression="execution(* org.my.service.impl.*.*(..))" /> 
        <aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointcut" />
    </aop:config>
</beans>
--------------------------------------------------------------------------------

你可能感兴趣的:(annotation)