spring配置文件

<?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:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop" 
       xmlns:tx="http://www.springframework.org/schema/tx" 
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd            
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/jee 
            http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
            http://www.springframework.org/schema/task    
            http://www.springframework.org/schema/task/spring-task-3.0.xsd
            http://www.springframework.org/schema/data/jpa 
            http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

    <description>Spring公共配置</description>
	
    <context:annotation-config />
	
		 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="locations">  
           <list>       
              <value>classpath:jdbc.properties</value> 
            </list>  
        </property>  
    </bean>  
	
	
    <bean id="applicationContextProvider" class="com.weinet.cardfolder.utils.ApplicationContextProvider"></bean>

    <!-- 使用annotation 自動註冊bean,並檢查@Required,@Autowired的屬性已被注入 -->
    <context:component-scan base-package="com.weinet.cardfolder" >
        <context:include-filter type="regex" expression=".view.*"/>
        <context:include-filter type="regex" expression=".service.*"/>
        <context:include-filter type="regex" expression=".model.*"/>
    </context:component-scan>
        
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="${url}"/>
        <property name="username" value="${username}"/>
        <property name="password" value="${password}"/>
        <property name="removeAbandoned" value="true"/>
        <property name="initialSize" value="20" />
        <property name="maxActive" value="30" />
    </bean> 
    
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan"  value="com.weinet.cardfolder.model" />
        <property name="persistenceUnitName" value="card_folder"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                <prop key="hibernate.max_fetch_depth">3</prop>
                <!--用於更新數據庫表結構,建議只有必要時再使用-->
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.jdbc.fetch_size">18</prop> 
                <prop key="hibernate.jdbc.batch_size">10</prop> 
                <prop key="hibernate.show_sql">false</prop> 
                <prop key="hibernate.format_sql">true</prop>
            </props>
        </property>
    </bean>
    
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">  
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>  
    <jpa:repositories base-package="com.weinet.cardfolder.repository" entity-manager-factory-ref="entityManagerFactory" 
            transaction-manager-ref="transactionManager"/>
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!-- vaadin spring integration -->
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:/locales/messages"/>
        <!-- Do not use System Locale file as default. Windows & Linux could have different default locale -->
        <property name="fallbackToSystemLocale" value="false" />
    </bean>

    <bean class="ru.xpoft.vaadin.VaadinMessageSource" />
    
       <!-- Enables the Spring Task @Scheduled programming model -->
    <task:executor id="executor" pool-size="1" />
    <task:scheduler id="scheduler" pool-size="1" />
    <task:annotation-driven executor="executor" scheduler="scheduler" />
</beans>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章