我想從一個上下文向MVC上下文中的控制器bean注入一個bean。下面是從MVC方面,我國bean定義:春天:春的DI批處理bean不起作用
<import resource="another.context.xml"/>
<bean name="myController" class="com.test.spring.web.Controller">
<property name="batchJobRepository" ref="batchJobRepository"/>
</bean>
在我定義了一個春天批處理作業存儲庫中的另一個方面:
<bean id="batchJobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
</bean>
我的控制器:
@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!";
}
的問題是一個棘手一。我得到一個錯誤:
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
我該如何解決它?
UPD
新增控制器的細節。
UPD2
我試圖用
<aop:scoped-proxy proxy-target-class="true"/>
在batchJobRepository
豆。但結果是一樣的:Failed to convert property value of type 'com.sun.proxy.$Proxy17 implementing org.springframework.batch.core.repository.JobRepository
你可以發佈所有類控制器嗎? – Abdelhak
當然。查看我的更新。 – Finkelson
我不明白。爲什麼你的控制器類有'@ Controller'註釋和相應的''聲明?另外,你爲什麼試圖注入一個'FactoryBean' bean而不是工廠創建的實際對象? –