Spring MVC定时服务
spring-mvc-config.xml
<context:component-scan base-package="com.bf" ></context:component-scan> <task:annotation-driven /> <mvc:annotation-driven />
spring-core-config.xml
<context:component-scan base-package="com.bf" > <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/> <!--需要保留此声明,以便单元测试可用--> </context:component-scan>
web.xml
<!-- For web context --> <servlet> <servlet-name>spring-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-mvc-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- For root context --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-core-config.xml</param-value> </context-param>
@Component public class AutoService { private static Logger logger = Logger.getLogger(AutoService.class); @Autowired private MemberWechatService memberWechatService; /* cron表达式: *(秒0-59) *(分钟0-59) *(小时0-23) *(日期1-31) *(月份1-12或是JAN-DEC) *(星期1-7或是SUN-SAT) */ @Scheduled(cron = "0 32 * * * *") //每周日下午6:00 public void notifyTutor() {
Server.xml
<Host autoDeploy="true" name="localhost" unpackWARs="true">
这种配置可以定义执行。
但是以下配置方式,对事务是有效的,感觉事务与定时服务有冲突,没找到解决办法
spring-mvc-config.xml
<context:component-scan base-package="com.bf" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan>
签名:删除冗余的代码最开心,找不到删除的代码最痛苦!