我将Spring Batch Admin集成到我的应用程序中,该应用程序使用Spring 3.2。
现在,我尝试使用@Scheduled
注释方法,并使用<task:annotation-driven/>
激活此方法。
当我启动webapp时,我得到了这个例外:
Caused by: java.lang.IllegalStateException: @Scheduled method 'removeInactiveExecutions'
found on bean target class 'SimpleJobService', but not found in any interface(s) for bean
JDK proxy. Either pull the method up to an interface or switch to subclass (CGLIB) proxies
by setting proxy-target-class/proxyTargetClass attribute to 'true'
Spring Batch Admin的SimpleJobService
在方法上使用此注释。
在Spring 3.2中。看起来,没有必要将cglib放入类路径中,而spring-asm也已经过时了。我从spring-batch-integration中排除了spring-asm
依赖。
我可以在哪里设置proxy-target-class=true
(我已经在<tx:annotation-config>
和<aop:config>
上试过了?
如何在我的应用程序中使用@Scheduled
?
答案 0 :(得分:2)
在META-INF \ spring \ batch \ override中添加execution-context.xml,将SimpleJobServiceFactoryBean的代理设置为目标类
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- Original jobRepository missing read ${batch.isolationlevel} -->
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" p:isolationLevelForCreate = "${batch.isolationlevel}"/>
<!-- Original jobService conflicted with @EnableScheduling -->
<bean id="jobService"
class="org.springframework.batch.admin.service.SimpleJobServiceFactoryBean">
<aop:scoped-proxy proxy-target-class="true" />
<property name="jobRepository" ref="jobRepository" />
<property name="jobLauncher" ref="jobLauncher" />
<property name="jobLocator" ref="jobRegistry" />
<property name="dataSource" ref="dataSource" />
<property name="jobExplorer" ref="jobExplorer" />
<property name="transactionManager" ref="transactionManager" />
</bean>
</beans>
答案 1 :(得分:-1)
方法removeInactiveExecutions
应该在实现类SimpleJobService