Spring @Autowire - java interface vs. scala trait

253 views
Skip to first unread message

Warren Strange

unread,
Mar 23, 2011, 8:29:20 PM3/23/11
to scala...@googlegroups.com

I have a small Spring / Scala app that is using Autowiring to inject dependencies. The relevant injection declaration is:

 @Inject
  var userRepo:UserRepository = _

If I declare the interface in Java everything works great:

@Transactional(readOnly = true)
public interface UserRepository extends JpaRepository<User,Long>{
}

The same interface declared as a Scala trait causes Spring to throw BeanCreationException (long stack trace omitted):

@Transactional(readOnly = true)
trait UserRepositoryXX  extends JpaRepository[User,java.lang.Long]   {
}


I gather this something to do with Spring's inability to create a proxy object for the scala trait? I understand that scala traits are not 100% the same as a Java interface. 

My question: Is there a workaround for this issue - or do I need to use Java interfaces?

Thanks

Warren


Warren Strange

unread,
Mar 23, 2011, 8:33:57 PM3/23/11
to scala...@googlegroups.com

Note:  The UserRepositoryXX()  trait in the example below is a posting cut n paste error  (should have been UserRepository).  
Reply all
Reply to author
Forward
0 new messages