3

我将 Spring Batch Admin 集成到我的应用程序中,该应用程序使用 Spring 3.2。

现在我尝试用 注释一个方法@Scheduled并用<task:annotation-driven/>. 当我启动 web 应用程序时,我得到了这个异常:

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'

SimpleJobServiceSpring Batch Admin 在方法上使用了这个注解。

在春季 3.2 中。似乎没有必要将 cglib 放入类路径中,并且 spring-asm 也已过时。spring-asm我从 spring-batch-integration 中排除了依赖项。

我可以在哪里设置proxy-target-class=true(我已经尝试过<tx:annotation-config><aop:config>

如何@Scheduled在我的应用程序中使用?

4

1 回答 1

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>
于 2015-12-22T10:57:38.373 回答