<?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" 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
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 扫描组件, 只扫描视图层的 @Controller、@ControllerAdvice -->
<context:component-scan base-package="cn.fg" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan>
<!-- 拦截器 -->
<!-- <mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/admin/**" />
<mvc:exclude-mapping path="/admin/index.do" />
<mvc:exclude-mapping path="/admin/login.do" />
<bean class="cn.fg.handlers.Interceptor.AdminInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors> -->
<!-- 视图解析器 -->
<!-- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/page/"></property>
<property name="suffix" value=".jsp"></property>
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
</bean> -->
<!-- 文件上传解析器 -->
<!-- <bean id="multipartResolver" class ="org.springframework.web.multipart.commons.CommonsMultipartResolver"> -->
<!-- <property name="maxUploadSize" value="10485760" /> --> <!-- 10M 单位:b ,默认不限制 -->
<!-- <property name="maxInMemorySize" value="102400" /> --> <!-- 100K 超过此设置将往硬盘写临时文件,默认10k -->
<!-- <property name="defaultEncoding" value ="UTF-8" /> --> <!-- 默认iso-8859-1 -->
<!-- </bean> -->
<!-- 开启后,页面静态资源(css、image、js)的请求由tomcat处理 -->
<mvc:default-servlet-handler />
<!-- mvc注解驱动 -->
<mvc:annotation-driven>
<!-- 报文转换器 -->
<!-- <mvc:message-converters> -->
<!--
解决返回类型为String,中文乱码的问题,例如:
@ResponseBody
public String test(){}
-->
<!-- <bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=utf-8</value>
<value>application/json;charset=utf-8</value>
</list>
</property>
</bean> -->
<!-- </mvc:message-converters> -->
</mvc:annotation-driven>
</beans>
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:cache="http://www.springframework.org/schema/cache"
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/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd ">
<!-- 扫描组件,排除视图层的组件 @Controller、@ControllerAdvice -->
<context:component-scan base-package="cn.fg">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan>
<!-- 加载属性文件 -->
<!-- <context:property-placeholder location="classpath:*.properties" /> -->
<!-- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file:d:\\conf.properties</value>
<value>classpath:db.properties</value>
</list>
</property>
</bean> -->
<import resource="spring-task.xml"/>
</beans>
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:cache="http://www.springframework.org/schema/cache"
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/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd ">
<!-- 任务注解驱动 @Scheduled @Async -->
<!--
scheduler(@Scheduled):指定调度方法的org.springframework.scheduling,与<task:scheduler /> 一起使用
可以是org.springframework.scheduling.TaskScheduler或者 java.util.ScheduledExecutorService的实例
不指定则以单线程运行调度任务
executor(@Async):指定异步方法调用的java.util.Executor,与<task:executor /> 一起使用,executor的值为@Async value 属性的缺省值
若不指定,则默认使用org.springframework.core.task.SimpleAsyncTaskExecutor实例
-->
<task:annotation-driven scheduler="taskScheduler" executor="taskExecutor" />
<!-- 调度器线程配置 -->
<!--
pool-size:线程池大小,默认为1
-->
<task:scheduler id="taskScheduler" pool-size="10" />
<!-- 执行器线程配置 -->
<!--
pool-size:执行程序线程池的大小,默认为1;可以是一个值,也可以是一个范围(例如5[corePoolSize]-10[maxPoolSize])。若为范围,则必须设置队列容量
queue-capacity:队列容量
keep-alive:空闲时间,默认60秒。当线程空闲时间达到后,该线程会退出,直到线程数量等于corePoolSize。如果allowCoreThreadTimeout设置为true,则所有线程均会退出直到线程数量为0。
rejection-policy:拒绝策略,当任务添加到线程池中被拒绝,而采取的处理措施
- ABORT:默认策略,它将抛出 RejectedExecutionException异常
- CALLER_RUNS:会使用当前正在运行的Thread线程(main线程)处理被拒绝的任务,不允许失败的任务可以采用此策略
- DISCARD: 直接丢弃
- DISCARD_OLDEST:放弃等待队列中最旧的未处理任务,然后将被拒绝的任务添加到等待队列中。
-->
<task:executor id="taskExecutor" pool-size="1" queue-capacity="10" keep-alive="20" />
<!--
固定线程数与队列关系:pool-size="5" queue-capacity="5" 使用LinkedBlockingQueue先进先出
-新建线程数 <= (核心线程数-执行中的线程数),线程不会加入到队列中
-新建线程数 > (核心线程数-执行中的线程数),线程加入到队列中;若队列数超过最大容量,则线程被拒绝执行;当出现空闲线程,队列中的任务就会被执行
-若不设置队列容量,则使用默认值Integer.MAX_VALUE
范围线程数与队列关系:pool-size="5-10" queue-capacity="10"
-新建线程数 <= (核心线程数-执行中的线程),线程不会加入到队列中
-新建线程数 > (核心线程数-执行中的线程)
-(新建线程数 + 队列中线程数) <= 队列最大容量,则线程加入到队列中
-(新建线程数 + 队列中线程数) > 队列最大容量,则不会加入到队里,而是增加池中的线程,使用池中新建的线程执行任务
-若新建线程数 > 最大线程数 且 > 队列最大容量,则超出的线程数会被拒绝
-->
</beans>
<!--web.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<!--<welcome-file-list>
<welcome-file>page/admin/login.jsp</welcome-file>
</welcome-file-list>-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
</web-app>