springmvc配置文件-1

时间:2022-12-10 21:44:07

项目1:

web.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="2.4"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>ProjectConsole</display-name>
    <description>Web UI</description>
    
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
    </context-param>

    
    <!-- springMVC -->
    <servlet>
        <servlet-name>servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/webmvc-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    
    
    
    <!-- Creates the Spring Container shared by all Servlets and Filters
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
     -->
    
    <!-- webapp do something -->
    <listener>
        <listener-class>com.vispractice.soa.lightesb.common.listener.EsbInitListener</listener-class>
    </listener>
    
    
    <!-- filter -->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    
    <filter>
        <filter-name>httpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>httpMethodFilter</filter-name>
        <servlet-name>servlet</servlet-name>
    </filter-mapping>

    <!-- session time out setting -->
    <filter>
        <filter-name>SessionTimeOutFilter</filter-name>
        <filter-class>com.vispractice.soa.lightesb.common.filter.SessionTimeOutFilter</filter-class>
        <init-param>
            <param-name>logout</param-name>
            <param-value>/WEB-INF/views/login.jsp</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>SessionTimeOutFilter</filter-name>
        <url-pattern>*.html</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>SessionTimeOutFilter</filter-name>
        <url-pattern>*.htm</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>SessionTimeOutFilter</filter-name>
        <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>SessionTimeOutFilter</filter-name>
        <url-pattern>*.do</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>SessionTimeOutFilter</filter-name>
        <url-pattern>*.json</url-pattern>
    </filter-mapping>

    <!-- DWR -->
    <servlet>
        <description>dwr-invoker</description>
        <servlet-name>dwr-invoker</servlet-name>
        <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
        <init-param>
            <param-name>classes</param-name>
            <param-value>com.vispractice.soa.lightesb.common.dwr.AutoTestCaseEvent</param-value>
        </init-param>
        <init-param>
            <param-name>debug</param-name>
            <param-value>true</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>dwr-invoker</servlet-name>
        <url-pattern>/dwr/*</url-pattern>
    </servlet-mapping>


    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

    <!-- welcome list -->
    <welcome-file-list>
        <welcome-file>/WEB-INF/views/login.jsp</welcome-file>
    </welcome-file-list>
    
    
    <!-- 以下为FLEX -->
    <!-- Http Flex Session attribute and binding listener support -->
    <listener>
        <listener-class>flex.messaging.HttpFlexSession</listener-class>
    </listener>

    <!-- MessageBroker Servlet -->
    <servlet>
        <servlet-name>MessageBrokerServlet</servlet-name>        
        <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
        <init-param>
            <param-name>services.configuration.file</param-name>
            <param-value>/WEB-INF/flex/services-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>    
    
    <servlet-mapping>
        <servlet-name>MessageBrokerServlet</servlet-name>
        <url-pattern>/messagebroker/*</url-pattern>
    </servlet-mapping>
</web-app>

webmvc-config.xml:

 

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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/mvc 
       http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <context:component-scan base-package="com.project.soa.light2esb">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
          <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> 
    </context:component-scan>
    
    <!-- root mapping
    <mvc:view-controller path="/" view-name="index"/>
    -->
    <mvc:annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving 
        up static resources -->
    <mvc:resources location="/, classpath:/META-INF/web-resources/"
        mapping="/resources/**" />

    <mvc:interceptors>
        <bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"/>
        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="lang"/>
    </mvc:interceptors>

    <mvc:default-servlet-handler />
    
    <bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="messageSource" p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application" p:fallbackToSystemLocale="false"/>
        <bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="errorSource" p:basenames="WEB-INF/i18n/errors" p:fallbackToSystemLocale="false"/>
        <!-- Store preferred language configuration in a cookie -->
    <bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver" id="localeResolver" p:cookieName="locale"/>
    <!-- Resolves localized <theme_name>.properties files in the classpath to allow for theme support -->
    <bean class="org.springframework.ui.context.support.ResourceBundleThemeSource" id="themeSource">
        <property name="basenamePrefix" value="theme-" />
    </bean>
    <!-- Store preferred theme configuration in a cookie -->
    <bean class="org.springframework.web.servlet.theme.CookieThemeResolver" id="themeResolver" p:cookieName="theme" p:defaultThemeName="default"/>

    <bean id="handlerExceptionResolver" class="com.project.vis.platform.web.servlet.mvc.support.PlatformHandlerExceptionResolver"/>
    
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"></bean>
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver"></bean>    
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>
    
    <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
        in the /WEB-INF/views directory -->
    <bean id="contentNegotiatingViewResolver"
        class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="order" value="#{T(org.springframework.core.Ordered).HIGHEST_PRECEDENCE}"/>
        <property name="mediaTypes">
            <map>
                <entry key="html" value="text/html" />
                <entry key="json" value="application/json" />
                <entry key="xml" value="application/xml" />
                <entry key="pdf" value="application/pdf" />
                <entry key="xsl" value="application/vnd.ms-excel" />
            </map>
        </property>
    </bean>
    
    <!--
    <bean id="resourceViewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="order" value="#{contentNegotiatingViewResolver.order+1}"/>
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>
    -->

    <bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="order" value="#{contentNegotiatingViewResolver.order+1}"/>
        <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
    </bean>
    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
          <list>
            <value>/WEB-INF/layouts/layouts.xml</value>
            <!-- Scan views directory for Tiles configurations -->
            <value>/WEB-INF/views/**/views.xml</value>
          </list>
        </property>
    </bean>
</beans>

applicationContext.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    <context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>

    <!-- 
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${database.driverClassName}"/>
        <property name="url" value="${database.url}"/>
        <property name="username" value="${database.username}"/>
        <property name="password" value="${database.password}"/>
        <property name="validationQuery" value="SELECT 1 FROM dual"/>
    </bean>
     -->
    
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>java:/datasources/visesbdb</value>
        </property>
    </bean>
    
    <!-- config dynamicDataSource -->
    <bean id="dynamicDataSource" class="com.vispractice.soa.lightesb.common.datasource.MutiDataSourceBean">
        <property name="targetDataSources">
            <map key-type="java.lang.String">
                <entry value-ref="dataSource" key="dataSource"></entry>
            </map>
        </property>
        <property name="defaultTargetDataSource" ref="dataSource"></property>
    </bean>
    
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dynamicDataSource"/>
        <property name="packagesToScan">
            <list>
                <value>com.vispractice.soa.lightesb.bean</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
        <prop key="connection.useUnicode">true</prop>
        <prop key="connection.characterEncoding">UTF-8</prop>
        <prop key="hibernate.dialect">${hibernate.dialect}</prop>
        <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
        <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
        <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
        <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
        <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
        </props>            
        </property>
    </bean>

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <!-- Activates scanning of @Autowired -->
    <context:annotation-config/>

    <context:component-scan base-package="com.vispractice.soa.lightesb">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> 
    </context:component-scan>

    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="10000000"/>
    </bean>

    <!-- proxy module -->
    <bean id="proxy" class="com.vispractice.soa.lightesb.proxy.impl.comm.ProxyCreatorImpl"/>
    <bean id="route" class="com.vispractice.soa.lightesb.proxy.impl.route.RouteCreatorImpl"/>    
</beans>


项目2:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    metadata-complete="true"
    version="2.5">
    <display-name>system-web</display-name>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
    
    <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>system-web.root</param-value>
    </context-param>
    
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath*:/applicationContext.xml,
            classpath*:/applicationContext-imports.xml
        </param-value>
    </context-param>
    <context-param>
        <param-name>spring.profiles.default</param-name>
        <param-value>development</param-value>
    </context-param>

    <!-- listener -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
    <listener>
        <listener-class>    
            org.springframework.web.context.request.RequestContextListener    
        </listener-class>    
    </listener>
    
    
    <!-- filter -->
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>openEntityManagerInViewFilter</filter-name>
        <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>openEntityManagerInViewFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>shiroFilter</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        <init-param>
            <param-name>targetFilterLifecycle</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>shiroFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <filter>
        <filter-name>sitemeshFilter</filter-name>        
        <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>        
    </filter>    
    <filter-mapping>
        <filter-name>sitemeshFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <!-- MVC -->
    <servlet>
        <servlet-name>springServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

spring-mvc.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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <!-- 自动扫描且只扫描@Controller -->
    <context:component-scan base-package="com.project" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
    </context:component-scan>

    <mvc:interceptors>  
       <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"></bean>
       <bean class="com.project.f10.system.controller.interceptor.PermissionResourceInterceptor"></bean> 
    </mvc:interceptors>
    
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" /> 
    
    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <!-- 将StringHttpMessageConverter的默认编码设为UTF-8 -->
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <constructor-arg value="UTF-8" />
            </bean>
            <!-- 将Jackson2HttpMessageConverter的默认格式化输出设为true -->
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                <property name="prettyPrint" value="true"/>
                <property name="supportedMediaTypes">
                  <list>
                    <value>application/json;charset=UTF-8</value>
                    <value>text/json;charset=UTF-8</value>
                  </list>
                 
            </property>
            </bean>            
          </mvc:message-converters>
    </mvc:annotation-driven>
    
    <!-- 定义JSP文件的位置 -->     
    <!-- 
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
    -->
    
    <bean id="contentNegotiatingViewResolver"
        class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="order" value="#{T(org.springframework.core.Ordered).HIGHEST_PRECEDENCE}"/>
        <property name="mediaTypes">
            <map>
                <entry key="html" value="text/html" />
                <entry key="json" value="application/json" />
                <entry key="text" value="text/json" />
                <entry key="xml" value="application/xml" />
                <entry key="pdf" value="application/pdf" />
                <entry key="xsl" value="application/vnd.ms-excel" />
            </map>
        </property>
    </bean>
    
    <bean id="resourceViewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="order" value="#{contentNegotiatingViewResolver.order+1}"/>
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />         
        <property name="prefix" value="/jsp/" />        
        <property name="suffix" value=".jsp" />
    </bean>
    
            
    <!-- 定义无需Controller的url<->view直接映射  redirect:-->
    <mvc:view-controller path="/" view-name="redirect:/login/success"/>
    
    <!-- 组件js文件位置 --> 
    <mvc:resources location="classpath:/META-INF/web-resources/" mapping="/web-resources/**" cache-period="31556926"/>
    
    <!-- 容器默认的DefaultServletHandler处理 所有静态内容与无RequestMapping处理的URL-->    
    <mvc:default-servlet-handler/>    
    
    
    <!-- 将Controller抛出的异常转到特定View, 保持SiteMesh的装饰效果 -->
      <!--  
    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">  
        <property name="exceptionMappings">
            <props>
                <prop key="java.lang.Throwable">common/error/error</prop>
                <prop key="java.lang.Exception">common/error/error</prop>
                <prop key="java.lang.RuntimeException">common/error/error</prop>
            </props>
        </property>
        <property name="statusCodes">
            <props>
                <prop key="common/error/404">404</prop>
                <prop key="common/error/error">500</prop>
            </props>
        </property>       
    </bean>
    -->
</beans>

 

applicationContext.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:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc"  
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd"
    default-lazy-init="true">

    <description>Spring公共配置 </description>

    <!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
    <context:component-scan base-package="com.project.**.dao,
                      com.project.**.service,
                      com.project.**.controller">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
    </context:component-scan>
    

    <!-- Spring Data Jpa配置 -->
     <jpa:repositories base-package="com.project.**.dao"  transaction-manager-ref="transactionManager" entity-manager-factory-ref="entityManagerFactory"/>
   
   
    <!-- 使用annotation定义事务 -->
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
    
    <!-- Jpa 事务配置 -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <!-- Jpa Entity Manager 配置 -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>        
        <property name="packagesToScan" value="com.project.**.entity"/>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
                <!--cache/ehcache-hibernate-local.xml  -->
                <prop key="net.sf.ehcache.configurationResourceName">cache/ehcache.xml</prop>
                <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
                
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                <prop key="hibernate.cache.use_query_cache">true</prop>
            </props>
        </property>
    </bean>
    
    <bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="databasePlatform">
            <bean factory-method="getDialect" class="com.project.modules.persistence.Hibernates">
                <constructor-arg ref="dataSource"/>
            </bean>
        </property>
    </bean>
    
    
    <!-- JSR303 Validator定义 -->
     <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" >
       <property name="validationMessageSource" ref="messageSource"/>
       <property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>
     </bean>
    
    <!-- 国际化文件配制,查找当前classpath以及jar包中的classpath,以第一个加载的属性KEY为主 -->
    <bean id="messageSource" class="com.project.f10.common.utils.ReloadableResourceBundleMessageSource">  
        <property name="fileEncodings" value="utf-8"/>
        <property name="basenames">
            <list>
                <value>classpath*:i18n/messages*</value>
            </list>
        </property>  
        <!-- 为flase 消息code必须存在,否则会抛出异常  如果为true,目前会导致validateMessages中的消息不能格式化 -->
        <property name="useCodeAsDefaultMessage" value="false"/>
    </bean>
    
    <!-- 加载所有的配制文件 -->
    <!-- 
    <context:property-placeholder  location="classpath*:conf/*.properties" ignore-unresolvable="true"/>
    
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">        
        <property name="basenames">
            <list>
                <value>i18n/messages</value>
                <value>i18n/messages_tips</value>
                <value>i18n/messages_operation_log</value>
            </list>
        </property>
        <property name="useCodeAsDefaultMessage" value="true"/>
    </bean>
    -->
    
    <!-- production环境 -->
     <beans profile="production">
         <context:property-placeholder ignore-unresolvable="true"
            location="classpath*:/application.properties,
                      classpath*:conf/*-config.properties"
                      />        
        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close">
            <property name="driverClass" value="${datasource.driverClassName}" />
            <property name="jdbcUrl" value="${datasource.url}" />
            <property name="user" value="${datasource.username}" />
            <property name="password" value="${datasource.password}" />
            <property name="acquireIncrement" value="${c3p0.acquireIncrement}" />
            <property name="initialPoolSize" value="${c3p0.initialPoolSize}" />
            <property name="minPoolSize" value="${c3p0.minPoolSize}" />
            <property name="maxPoolSize" value="${c3p0.maxPoolSize}" />
            <property name="maxIdleTime" value="${c3p0.maxIdleTime}" />
            <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}" />
            <property name="maxStatements" value="${c3p0.maxStatements}" />
            <property name="numHelperThreads" value="${c3p0.numHelperThreads}" />
       </bean>        
    </beans>
    
    <!-- local development环境 -->
    <beans profile="development">
        <context:property-placeholder ignore-resource-not-found="true" 
            location="classpath*:/application.properties,
                        classpath*:/application.development.properties,
                        classpath*:/conf/*.development.properties
                        " />    
        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close">
            <property name="driverClass" value="${datasource.driverClassName}" />
            <property name="jdbcUrl" value="${datasource.url}" />
            <property name="user" value="${datasource.username}" />
            <property name="password" value="${datasource.password}" />
            <property name="acquireIncrement" value="${c3p0.acquireIncrement}" />
            <property name="initialPoolSize" value="${c3p0.initialPoolSize}" />
            <property name="minPoolSize" value="${c3p0.minPoolSize}" />
            <property name="maxPoolSize" value="${c3p0.maxPoolSize}" />
            <property name="maxIdleTime" value="${c3p0.maxIdleTime}" />
            <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}" />
            <property name="maxStatements" value="${c3p0.maxStatements}" />
            <property name="numHelperThreads" value="${c3p0.numHelperThreads}" />
       </bean>
    </beans>
    
    <!-- functional test 环境 -->
    <beans profile="functional">
        <context:property-placeholder ignore-resource-not-found="true"
            location="classpath*:/application.properties,
                        classpath*:/application.functional.properties,
                        classpath*:/conf/*.functional.properties" />    

        <!-- Tomcat JDBC连接池 -->
        <bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
            <property name="driverClassName" value="${jdbc.driver}" />
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
            <property name="defaultAutoCommit" value="false" />
        </bean>
        <!-- 初始化数据表结构 -->
        <!--  
        <jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
            <jdbc:script location="classpath*:sql/${db.type}/schema.sql" encoding="UTF-8"/>
            <jdbc:script location="classpath*:sql/${db.type}/views.sql" encoding="UTF-8"/>
            <jdbc:script location="classpath*:sql/${db.type}/data/import-data.sql" encoding="UTF-8"/>
        </jdbc:initialize-database>    
        -->
    </beans>
    
    <!-- unit test环境 -->
    <beans profile="test">
         <context:property-placeholder ignore-resource-not-found="true"
            location="classpath*:/application.test.properties,
                        classpath*:/conf/*.test.properties
                        " />    
        
        <!-- Spring Simple连接池 -->
        <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
            <property name="driverClass" value="${jdbc.driver}" />
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
        </bean>
    </beans>
    
    <!-- standalone环境 -->
    <beans profile="standalone">
         <context:property-placeholder ignore-resource-not-found="true"
            location="classpath*:/application.properties,
                        classpath*:/application.standalone.properties,
                        classpath*:/conf/*.standalone.properties" />    
        
        <!-- Spring Simple连接池 -->
        <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
            <property name="driverClass" value="${jdbc.driver}" />
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
        </bean>
    </beans>
    
</beans>