我需要从实现的类中Runnable
打开我的 Java EE 应用程序 7 Spring MVC。我在以下声明我的班级servlet.xml
:
<beans:bean class="MyClass" scope="singleton">
</beans:bean>
<annotation-driven />
<context:component-scan base-package="MyClass" />
<context:annotation-config />
这是我的班级,它有一个run()
从所有 X 分钟开始的方法,但它不起作用。为什么?
@Scope("singleton")
@Component
public class MyClass implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(myClass.class);
@Scheduled(initialDelay = 1000, fixedDelay = 10000)
@Override
@Transactional
public void run() {
LOG.debug("IN");
}
}
我的 servlet.xml :
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
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/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<context:annotation-config />
<context:component-scan base-package="com" />
<jpa:repositories base-package="com.dao" />
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources
directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<beans:bean class="com.MyClass" scope="singleton">
</beans:bean>