, and when I fire up tomcat the controller that gets @Autowired with this service bean can't find an autowire candidate. I was beating myself up trying to figure out why it couldn't find a candidate object, when the @Service object was clearly getting instantiated (I could see this via log4j debug messages). I eventually decided to simplify by commenting out the < tx:annotation-driven / >, and voila! The webapp starts fine.
Can someone provide a technical reason why this doesn't work? I'm about to try @Qualifier to see if that "fixes" the problem.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
当您将
添加到配置中时,它会导致代理类发生各种包装(请参阅 Spring 事务文档)。这可能与 @Transactional 注释和 Scala 配合得不好。请参阅在 Scala 中使用 Spring @Transactional
When you add
<tx:annotation-driven/>
to your configuration, it causes various wrapping to happen with proxy classes (see the Spring documentation on transactions). This probably isn't playing well with the @Transactional annotation and Scala.See Use Spring @Transactional in Scala
所以我弄清楚了我的问题。实际上,它可能已经被 java 和 scala 所“破坏”了。我的服务类仅包含一个实现类,没有接口。一旦 @Transactional 代理,类 spring 就无法找到自动装配候选者。只需添加一个接口(或 scala 中的特征)即可解决该问题。
So I figured out my issue. It actually may have been "broken" with java as well as scala. My service class consisted only of an implementation class and no interface. Once @Transactional proxied the class spring was unable to find an autowire candidate. Simply adding an interface (or trait in scala) fixed the issue.