Search code examples
javaspringhibernateautowiredcomponent-scan

Can I use @ComponentScan and @Autowired with BasicDataSource without declare bean for BasicDataSource class in XML?


I'm trying to integrate hibernate with spring, and I asked-just to know if that possible or not-, can I use @Autowired and @Componentscan to do inject the BasicDataSource class?


Solution

  • With @ComponentScan you can avoid declaring beans by loading them from Java-based configurations. This way, you still need a @Configuration to provide a BasicDataSource dependency.

    After the BasicDataSource dependency is scanned, it can be injected in other Spring components using @Autowired or @Inject.