zj
2024-06-03 4afe73cb84c5a609662b8b4ee20693de9b86b9a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
       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">
 
    <!--这里只扫描controller的bean,并关掉默认扫描 use-default-filters="false"-->
    <context:component-scan base-package="com.nq.controller" annotation-config="true" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
 
    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean 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>
            <!--springmvc进行自动反序列化时采用的类,jackson-->
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
                <!--此处可以配置,例如返回对象时,空值不返回-->
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
                <!--前端传入对象中不存在的值,忽略-->
                <!--<property name="objectMapper" ref="MyJsonMapper" />-->
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
 
    <bean id="MyJsonMapper" class="com.nq.common.converter.MyJsonMapper"></bean>
 
 
    <!-- 文件上传 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="10485760"/> <!-- 10m -->
        <property name="maxInMemorySize" value="4096" />
        <property name="defaultEncoding" value="UTF-8"></property>
    </bean>
 
    <!--spring mvc拦截器 - 拦截为登陆     -->
 
 
    <!-- user interceptor-->
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/user/**"/>
            <bean class="com.nq.common.interceptor.ApiUserAuthorityInterceptor" />
        </mvc:interceptor>
    </mvc:interceptors>
 
    <!-- agent interceptor-->
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/agent/**"/>
            <bean class="com.nq.common.interceptor.ApiAgentAuthorityInterceptor" />
        </mvc:interceptor>
    </mvc:interceptors>
 
    <!-- admin interceptor-->
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/admin/**"/>
            <bean class="com.nq.common.interceptor.ApiAdminAuthorityInterceptor" />
        </mvc:interceptor>
    </mvc:interceptors>
 
 
    <!--freemarker 模版引擎配置-->
    <bean id="freemarkerConfig"
          class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <property name="defaultEncoding" value="utf-8" />
        <!--这里也可以配置页面的地址    /WEB-INF/templates -->
        <property name="templateLoaderPath" value="" />
        <property name="freemarkerSettings">
            <props>
                <!--设置标签类型,有[]和<>这两种,但是<>这种要快-->
                <prop key="tag_syntax">auto_detect</prop>
                <!--模版更新时间,默认5s ,dev环境的时候修改0,热部署-->
                <prop key="template_update_delay">0</prop>
                <prop key="locale">zh_CN</prop>
                <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop><!-- 时间格式化 -->
                <prop key="date_format">yyyy-MM-dd</prop>
                <prop key="time_format">HH:mm:ss</prop>
                <prop key="number_format">#.####</prop>
                <!--去掉多余的空格-->
                <prop key="whitespace_stripping">true</prop>
                <!--自动加载 自定义的宏文件-->
                <prop key="auto_import">/WEB-INF/ftl/myftl.ftl as s</prop>
            </props>
        </property>
        <!--freemarker自定义宏指令-->
        <!--<property name="freemarkerVariables">-->
            <!--<map>-->
                <!--<entry key="role" value-ref="roleDirectiveModel" />-->
            <!--</map>-->
        <!--</property>-->
    </bean>
    <!--显式的配置 freemarker 的自定义指令bean-->
    <!--<bean id="roleDirectiveModel" class="com.nq.utils.RoleDirectiveModel" />-->
    <!--可以独立出来一个 freemarker.properties 文件-->
    <!--<bean id="freemarkerConfig"-->
    <!--class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">-->
    <!--<property name="location" value="classpath:freemarker.properties" />-->
    <!--</bean>-->
    <!-- 配置freeMarker视图解析器 -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
        <property name="contentType" value="text/html; charset=utf-8" />
        <property name="prefix" value="" />
        <property name="suffix" value=".html" />
        <property name="cache" value="true" />
    </bean>
 
 
    <!-- 配置验证码 -->
    <bean id="captchaProducer" class="com.google.code.kaptcha.impl.DefaultKaptcha">
        <property name="config">
            <bean class="com.google.code.kaptcha.util.Config">
                <constructor-arg>
                    <props> <!-- 图片边框 -->
                        <prop key="kaptcha.border">no</prop>
                        <!-- 图片宽度 -->
                        <prop key="kaptcha.image.width">100</prop>
                        <!-- 图片高度 -->
                        <prop key="kaptcha.image.height">45</prop>
                        <!-- 验证码背景颜色渐变,开始颜色 -->
                        <!--<prop key="kaptcha.background.clear.from">248,248,248</prop>-->
                        <!-- 验证码背景颜色渐变,结束颜色 -->
                        <!--<prop key="kaptcha.background.clear.to">248,248,248</prop>-->
                        <!-- 验证码的字符 -->
                        <prop key="kaptcha.textproducer.char.string">0123456789abcdefg</prop>
                        <!-- 验证码字体颜色 -->
                        <prop key="kaptcha.textproducer.font.color">red</prop>
                        <!-- 验证码的效果,水纹 -->
                        <!--<prop key="kaptcha.obscurificator.impl">com.google.code.kaptcha.impl.WaterRipple</prop>-->
                        <!-- 验证码字体大小 -->
                        <prop key="kaptcha.textproducer.font.size">33</prop>
                        <!-- 验证码字数 -->
                        <prop key="kaptcha.textproducer.char.length">4</prop>
                        <!-- 验证码文字间距 -->
                        <prop key="kaptcha.textproducer.char.space">5</prop>
                        <!-- 验证码字体 -->
                        <prop key="kaptcha.textproducer.font.names">
                            宋体,楷体,微软雅黑
                        </prop>
                        <!-- 不加噪声 -->
                        <prop key="kaptcha.noise.impl">com.google.code.kaptcha.impl.NoNoise</prop>
                    </props>
                </constructor-arg>
            </bean>
        </property>
    </bean>
 
</beans>