SpringMVC开启定时任务

时间:2022-06-10 21:36:00

参考博客:

http://www.cnblogs.com/xing901022/p/4264078.html

http://www.cnblogs.com/liaojie970/p/5913272.html

 

搭建完SpringMVC后要开启定时任务,添加以下:

xmlns:task="http://www.springframework.org/schema/task"

http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd

<task:annotation-driven />
<!-- 配置自动扫描的包 -->
<context:component-scan base-package="com.xxx"></context:component-scan>

SpringMVC开启定时任务

添加了之后,启动报错如下:

Error creating bean with name 'org.springframework.context.annotation.internalAsyncAnnotationProcessor': 
Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice
警告: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'org.springframework.context.annotation.internalAsyncAnnotationProcessor': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:
547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:
476)
at org.springframework.beans.factory.support.AbstractBeanFactory$
1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:
230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:
299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:
199)
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:
220)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:
615)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:
465)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:
663)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:
629)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:
677)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:
548)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:
489)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:
136)
at javax.servlet.GenericServlet.init(GenericServlet.java:
158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:
1284)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:
1197)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:
1087)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:
5266)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:
5554)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:
150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:
1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:
1565)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

解决:

添加jar:aopalliance-1.0.jar

下载地址:http://pan.baidu.com/s/1sjHOLIl?errno=0&errmsg=Auth%20Login%20Sucess&&bduss=&ssnerror=0