3
votes

I integrated Spring Batch Admin into my app, which uses Spring 3.2.

Now I try to annotate a method with @Scheduled and activate this with <task:annotation-driven/>. When I launch the webapp I get this exception:

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'

The SimpleJobService of Spring Batch Admin uses this annotation on a method.

In Spring 3.2. it seems, that there is no need to put cglib into the classpath and spring-asm is obsolete, too. I excluded the spring-asm dependency from spring-batch-integration.

Where can I set proxy-target-class=true (I already tried it on <tx:annotation-config> and <aop:config>?

How can I use @Scheduled in my application?

1
Is there an interface for the SimpleJobService?Manuel Quinones
Yes, its JobService. However, the annotated method is not member of the interface.timomeinen
I found a raleted ticket in Springs Jira: jira.springsource.org/browse/BATCHADM-126 But the advised solution doesn't work with Spring 3.2. Fortunately, I can answer my question, where to set the proxy-target-class: It should be on the task-namespace element, which is not supported by Spring at the moment.timomeinen
how did you end up getting past this?Hendrik
@Hendrik I worked around the problem with the task context of Spring. I created a XML file and use the <task:scheduled-tasks> element to create a scheduler on a bean e.g. <task:scheduled ref="jobRunner" method="launchTheJob" cron="0 0 12 * * MON-FRI"/>.timomeinen

1 Answers

2
votes

Add execution-context.xml in META-INF\spring\batch\override, set proxy of SimpleJobServiceFactoryBean to target class

<?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>