I want to inject a bean from one context to my controller bean in MVC context. Here is my bean definition from MVC context:
<import resource="another.context.xml"/>
<bean name="myController" class="com.test.spring.web.Controller">
<property name="batchJobRepository" ref="batchJobRepository"/>
</bean>
In the another context I defined a Spring Batch Job repository:
<bean id="batchJobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
</bean>
My controller:
@Controller
public class MyController {
private MapJobRepositoryFactoryBean batchJobRepository;
@RequestMapping("/batch/test")
@ResponseBody
public String batch() {
Set<JobExecution> jes = batchJobRepository
.getJobExecutionDao()
.findRunningJobExecutions("firstJob");
for (JobExecution je : jes) {
System.out.println(je.isRunning());
}
return "Done!";
}
The problem is a tricky one. I got an error:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'myController' defined in class path resource [META-INF/spring/controllers.xml]:
Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException:
Failed to convert property value of type 'com.sun.proxy.$Proxy25 implementing org.springframework.batch.core.repository.JobRepository,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean' for property 'batchJobRepository';
nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy25 implementing org.springframework.batch.core.repository.JobRepository,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean] for property 'batchJobRepository': no matching editors or conversion strategy found
How can I fix it?
UPD
Added controller details.
UPD2
I tried to use
<aop:scoped-proxy proxy-target-class="true"/>
in batchJobRepository
bean. But result is the same: Failed to convert property value of type 'com.sun.proxy.$Proxy17 implementing org.springframework.batch.core.repository.JobRepository