我将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
? 最佳答案
在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>