spring-web-context.xml 6.45 KB
<?xml  version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:task="http://www.springframework.org/schema/task" xmlns:util="http://www.springframework.org/schema/util"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p"
       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/util
                        http://www.springframework.org/schema/util/spring-util.xsd
                        http://www.springframework.org/schema/aop
                        http://www.springframework.org/schema/aop/spring-aop.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">
    <mvc:resources mapping="/html/**" location="/html/"/>
    <aop:aspectj-autoproxy/>
    <context:property-placeholder ignore-resource-not-found="true" location="classpath*:config.properties"/>

    <context:component-scan base-package="com.yohoufo"/>

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

    <bean id="stringRedisSerializer"
          class="org.springframework.data.redis.serializer.StringRedisSerializer"/>


    <!-- byte[] 转换器 -->
    <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>

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

    <!-- json转换器 application/json -->
    <bean id="jsonConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
        <property name="supportedMediaTypes" value="application/json;charset=UTF-8"/>
        <property name="fastJsonConfig" ref="fastJsonConfig"/>
    </bean>

    <bean id="fastJsonConfig" class="com.alibaba.fastjson.support.config.FastJsonConfig">
        <property name="serializerFeatures">
            <array value-type="com.alibaba.fastjson.serializer.SerializerFeature">
                <value>WriteEnumUsingToString</value>
                <value>DisableCircularReferenceDetect</value>
            </array>
        </property>
    </bean>
    <bean id="DisableCircularReferenceDetect"
          class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
        <property name="staticField"
                  value="com.alibaba.fastjson.serializer.SerializerFeature.DisableCircularReferenceDetect"></property>
    </bean>


    <!-- 配置MultipartResolver 用于文件上传 使用spring的CommosMultipartResolver -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="UTF-8"></property>
        <property name="resolveLazily" value="true"></property>
    </bean>


    <task:annotation-driven executor="myExecutor"
                            scheduler="myScheduler"/>
    <task:executor id="myExecutor" pool-size="5"/>
    <task:scheduler id="myScheduler" pool-size="10"/>

    <bean id="handlebarsViewResolver" class="com.github.jknack.handlebars.springmvc.HandlebarsViewResolver">
        <property name="prefix" value="classpath:/conf/template"/>
        <property name="suffix" value=".html"/>
        <property name="contentType" value="text/html;charset=UTF-8"/>
    </bean>

    <!-- api文档配置  start -->
    <!-- api文档配置  注解扫描器 -->
    <bean id="yohoApiAnnotationScanner" class="com.yoho.tools.docs.YohoApiAnnotationScanner">
        <!-- api文档配置  类名过滤器(正则)多个模式用英文逗号隔开 -->
        <property name="classFilterReg" value="${yoho.api.docs.filter:^.*$}"/>
        <property name="scanSwitch" value="${yoho.api.docs.switch:off}"/>
    </bean>
    <!-- api文档配置  end -->

    <bean id="ufoServiceCaller" class="com.yohoufo.common.caller.UfoServiceCaller"/>


    <bean id="eventBusPublisher" class="com.yohoufo.common.alarm.EventBusPublisher">
        <constructor-arg name="executor" ref="executor"/>
    </bean>

    <task:executor id="executor" pool-size="20"/>
    <bean id="accessStatistics" class="com.yohoufo.common.interceptor.AccessStatistics"/>
    <!--Spring mvc 拦截器-->
    <mvc:interceptors>
        <ref bean="trace.traceInterceptor"/>
        <ref bean="threadProfileInterceptor"/>
        <ref bean="localIpInterceptor"/>
        <ref bean="securityInterceptor"/>
        <ref bean="signatureVerifyInterceptor"/>
        <ref bean="innerApiInterceptor"/>
        <ref bean="accessStatistics"/>
        <ref bean="bodyParamCheckInterceptor"/>
    </mvc:interceptors>


    <!-- 上报influxdb 事件 -->
    <bean id="ufoInfluxdbEventHandler" class="com.yohoufo.common.alarm.UfoInfluxdbEventHandler">
        <property name="eventReporter" ref="eventReporter"/>
        <property name="tag_context" value="${web.context:default}"/>
        <!--<property name="cloud" value="${cloud:qcloud}"/>-->
    </bean>

    <aop:config>
        <aop:pointcut id="ufoMethodProfilePointcut"
                      expression="
					      (execution(* com.yohoufo.*.controller..*.*(..)))
					   or (execution(* com.yohoufo.common.cache.ControllerCacheAop.*(..)))
					   or (execution(* com.yoho.core.redis.YH*Operations.*(..)))
					   or (execution(* com.yoho.core.redis.cluster.operations.nosync.*.*(..)))"/>
        <aop:advisor pointcut-ref="ufoMethodProfilePointcut" advice-ref="serviceMethodInterceptor"/>
    </aop:config>

</beans>