gpt4 book ai didi

spring - 如何将 Spring Batch Admin 与 Spring 3.2 和 @Schedule 注释一起使用?

转载 作者:行者123 更新时间:2023-12-01 11:55:24 25 4
gpt4 key购买 nike

我将 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'

SimpleJobService Spring Batch Admin 在方法上使用此注释。

在 Spring 3.2 中。似乎没有必要将 cglib 放入类路径中,spring-asm 也已过时。我排除了 spring-asm来自 spring-batch-integration 的依赖。

我在哪里可以设置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>

关于spring - 如何将 Spring Batch Admin 与 Spring 3.2 和 @Schedule 注释一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14265076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com