spring context 例子

来源:互联网 发布:淘宝店淘金币怎么设置 编辑:程序博客网 时间:2024/05/16 17:52
<?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:c="http://www.springframework.org/schema/c"
  xmlns:cache="http://www.springframework.org/schema/cache"
  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:lang="http://www.springframework.org/schema/lang"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xmlns:p="http://www.springframework.org/schema/p"
  xmlns:task="http://www.springframework.org/schema/task"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:util="http://www.springframework.org/schema/util"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">


  <context:component-scan base-package="com.lee" />
  <bean class="org.springframework.validation.beanvalidation.MethodValidationPostProcessor" />
  <mvc:annotation-driven>
    <mvc:message-converters>
      <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
        <property name="objectMapper" ref="myJacksonObjectMapper" />
      </bean>
    </mvc:message-converters>
  </mvc:annotation-driven>
 
  <bean id="keyGenerator" class="com.lee.CacheKeyGenerator"/>
  <cache:annotation-driven cache-manager="cacheManager" key-generator="keyGenerator"/>
  
  <tx:annotation-driven transaction-manager="transactionManager" />
  
  <aop:config>
    <aop:aspect id="logAspect" ref="logAspect">
      <aop:pointcut expression="execution(* com.lee.service.impl.*.*(..))" id="service"/>
      <aop:around pointcut-ref="service" method="doAround"/>
      
      <aop:pointcut expression="execution(* com.lee.controller.*.*(..))" id="controller"/>
      <aop:around pointcut-ref="controller" method="doAround"/>
    </aop:aspect>
  </aop:config>
  
  <bean id="logAspect" class="com.fil.ap.api.framework.interceptor.LoggingInterceptor"/>
  
  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="myDataSource" />
  </bean>


  <bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/MYDataSource" />
    <property name="resourceRef" value="true" />
  </bean>


  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="myDaffeDataSource" />
    <property name="mapperLocations" value="classpath*:mappers/**/*.xml" />
  </bean>


  <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
    <constructor-arg index="0" ref="sqlSessionFactory" />
  </bean>


  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="annotationClass" value="org.springframework.stereotype.Repository"/>
    <property name="basePackage" value="com.fil.ap.api.hk.retail.mapper" />
    <!-- need below line when there're more than one data sources -->
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
  </bean>


  <bean id="myJacksonObjectMapper" class="com.lee.MyJacksonObjectMapper" />  

  <mvc:interceptors>  
    <mvc:interceptor>
      <mvc:mapping path="/*"/>
      <bean id="myInterceptor1" class="com.lee.MyInterceptor1"/>
    </mvc:interceptor>
    <mvc:interceptor>
      <mvc:mapping path="/*"/>
      <bean id="myInterceptor2" class="com.lee.MyInterceptor2"/>
    </mvc:interceptor>
  </mvc:interceptors>

</beans>



----------------------------------------------分割线----------------------------------------------
<!--ehcache-->
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache" />
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:config-location="classpath:ehcache.xml" p:shared="true" />  

0 0