Reputation: 6517
I have created a few interfaces extending CrudRepository
. I'd like to use them into a generic class that is not a bean. What I do currently is to inject them using @Autowired
inside my RestController
and then pass them down as method arguments to this generic class I'm talking about. Is there a better way to achieve this?
Upvotes: 0
Views: 48
Reputation: 1295
One approach is to make your unmanaged class extending SpringBeanAutowiringSupport and use @Autowired properties. If your application has a Spring web application context, it can then try to get the context from the current thread and resolve the @Autowired properties for you.
Upvotes: 1