1

I'm using spring+scala 2.8. I have a @Transactional bean (marked with @Service), that is enabled in spring via < tx:annotation-driven / >, 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.

Kevin
  • 24,871
  • 19
  • 102
  • 158

2 Answers2

0

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

Community
  • 1
  • 1
Emil Sit
  • 22,894
  • 7
  • 53
  • 75
  • I think you're on the right track with the bit about proxying. I'm not sure if the thread you link to is entirely relevent though...because my transactional beans are spring managed via service annotation. – Kevin Apr 02 '11 at 05:25
  • You'd have to investigate how @Transactional in Scala interacts with the implementation of tx:annotation-driven. Again, some example source and application context files would probably help. – Emil Sit Apr 02 '11 at 16:45
0

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.

Kevin
  • 24,871
  • 19
  • 102
  • 158