I am trying to use Spring with Scala. I know Autowired works with Scala class, but I am using a web-framework that requires an object and I want to inject a dao into it. I w
Normal Autowire from a class that is marked with @Component or @Bean would work with above mentioned ways.
But if you want to auto wire an interface extending Jpa repository then make sure the Dao is not an object but class.
ex:
DAO:
object dao{
@Autowired val repo: jpaRepo = null
}
This won't work (tested). My guess is that since it's defined as an object, gets instantiated at run time with repo as null value, hence won't be able to autowire jpa repo.
Instead declare it as class and mark with @Component:
@Component
class dao{
@Autowired val repo: jpaRepo = null
}
It works since we are letting spring to manage the object creation(@component) that autowires jpa repo properly.