`

Spring 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/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc.xsd">


  <!--
      自动为spring容器中那些配置@aspectJ切面的bean创建代理,织入切面。
      proxy-target-class属性默认为false,表示使用jdk动态代理织入增强,当配为<aop:aspectj-autoproxy proxy-target-class="true"/>时,表示使用CGLib动态代理技术织入增强。不过即使proxy-target-class设置为false,如果目标类没有声明接口,则spring将自动使用CGLib动态代理。 
   -->
<!-- <aop:aspectj-autoproxy /> --> 


<!--配置变量注入 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath*:config/*.properties</value>
            <value>classpath*:prod.properties</value>
            <value>file://${app_conf}/prod.properties</value>
        </list>
    </property>
    <property name="ignoreResourceNotFound" value="true"/>
</bean>
<!--
    <mvc:annotation-driven />会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的。
    若配置了静态资源访问,比如<mvc:resources mapping="/XXX/**" location="/XXX/"/>,则不能省略该配置,否则无法匹配到对应的handler(即需要的接口)
-->
<mvc:annotation-driven/>
<!--
    <context:annotation-config/>会自动向 Spring 容器注册AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、PersistenceAnnotationBeanPostProcessor
    以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。注册这4个 BeanPostProcessor的作用,就是为了你的系统能够识别相应的注解。

    如果你想使用@Autowired注解,那么就必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。
    如果想使用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor。
    如果想使用@PersistenceContext注解,就必须声明PersistenceAnnotationBeanPostProcessor的Bean。
    如果想使用 @Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。
-->
<context:annotation-config/>
<!--
    指定Spring组件扫描的基本包路径 ,还可以通过<context:include-filter type="XXX" expression="XXX"/> 或 <context:exclude-filter type="XXX" expression="XXX"/>进行过滤
-->
<context:component-scan base-package="com.linyp.weixin"/>

<!-- 静态资源访问 -->
<mvc:resources mapping="/images/**" location="/images/"/>

<!-- 载入配置 -->
<import resource="classpath*:spring/servlet-context.xml"/>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics