Using @Autowired spring with scala

I am using spring from scala and I ran into a problem when trying to enter a service using the attribute / superclass.

This is my code:

trait MyServiceHolder{ var myService:MyService = null @Autowired def setMyService(ms:MyService) = myService = ms } @RunWith(classOf[SpringJUnit4ClassRunner]) @ContextConfiguration(Array("file:src/main/webapp/WEB-INF/application-context.xml")) class MyConcreteClass extends MyServiceHolder{ def hello() = myService.hello() } 

It works:

 @RunWith(classOf[SpringJUnit4ClassRunner]) @ContextConfiguration(Array("file:src/main/webapp/WEB-INF/application-context.xml")) class MyConcreteClass{ var myService:MyService = null @Autowired def setMyService(ms:MyService) = myService = ms def hello() = myService.hello() } 

The problem is that myService is null in my test files. When viewing the bytecode level (class file), all annotations are present. Any ideas?

+4
source share
1 answer

You need to use the Spring TestContext Framework form so that your beans is configured for Spring when running the tests.

+3
source

All Articles