spring-web-context.xml 3.58 KB
<?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:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd
                        http://www.springframework.org/schema/aop
                        http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
                        http://www.springframework.org/schema/task
                        http://www.springframework.org/schema/task/spring-task.xsd">

    <!-- Spring扫描目录,通过注解的方式注入bean,只扫描本工程的目录 -->
    <context:component-scan base-package="com.yoho.search" />

    <!-- 打开aop 注解 -->
    <aop:aspectj-autoproxy proxy-target-class="true"/>

    <bean id="searchConfigServerPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreUnresolvablePlaceholders" value="true" />
        <property name="locations">
            <list>
                <value>classpath:config.properties</value>
            </list>
        </property>
    </bean>


    <!-- 服务错误码异常处理 -->
    <bean class="com.yoho.error.exception.handler.ServiceGlobalExceptionHandler" ></bean>

    <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
    <mvc:annotation-driven>
        <mvc:message-converters>
            <ref bean="stringConverter" />
            <ref bean="jsonConverter" />
        </mvc:message-converters>
    </mvc:annotation-driven>

    <mvc:interceptors>
        <ref bean="threadProfileInterceptor"/>
    </mvc:interceptors>

    <!--字符串转换器-->
    <bean id="stringConverter"
          class="org.springframework.http.converter.StringHttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/plain;charset=UTF-8</value>
            </list>
        </property>
    </bean>


    <!-- json转换器  application/json -->
    <bean id="jsonConverter"
          class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
        <property name="features">
            <array value-type="com.alibaba.fastjson.serializer.SerializerFeature">
                <value>DisableCircularReferenceDetect</value>
            </array>
        </property>
    </bean>

    <!-- <task:annotation-driven/>  -->

   <!--service接口调用拦截器-->
    <bean id="serviceMethodInterceptor" class="com.yoho.core.common.monitor.interceptor.MethodProfileInterceptor">
    </bean>
    <aop:config>
        <aop:pointcut id="serviceMethodPoint"
                      expression="(execution(* com.yoho.*.*.service.*.*(..))) or (execution(* com.yoho.*.*.service.impl.*.*(..))) or (execution(* com.yoho.*.*.restapi.*.*(..)))
					  "/>
        <aop:advisor pointcut-ref="serviceMethodPoint" advice-ref="serviceMethodInterceptor"/>
    </aop:config>

</beans>