首页 > 代码库 > Spring MVC定时服务
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>
@Componentpublic 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>
Spring MVC定时服务
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。