public interface Service {
public void doSomething();
}
@Service
public class MyService implements service{
@Transactional
public void doSomething(){
}
}
@Controller
public class MyController {
@Autowired
private MyService service;
}
在上述情况下,自动装配失败,例外“illegalArgumentException : argument type mismatch
”。当我从MyService中删除implements service
时,一切正常。弹簧豆执行接口
我已经搜索并发现在applicationContext.xml中的地方<aop:aspectj-autoproxy proxy-target-class="true"/>
成功的自动装配和它的工作。 我还发现,当使用@Transactional时,Spring使用JDK代理。
我有一些困惑,
- 如何@Transactional涉及到代理
- 为什么Spring使用JDK代理为它实现的接口豆。
- 为什么我需要把
<aop:aspectj-autoproxy proxy-target-class="true"/>
在applicationContext.xml中
任何人都可以请解释?或向我推荐任何文章或博客
服务 - >服务? – abalogh