I need help understanding the concept behind @Autowired
and @Service
. I have a DAO defined with @Service
and controller with @Autowi
When using classpath scanning, you have to communicate to Spring which classes to manage. This is done using the @Service
annotation, and its relations (@Controller
, @Repository
, etc).
If you choose not to annotate your bean, you must explicitly declare it in your config, just like you did with dataSource
and jdbcTemplate
.
Annotating your classes means only those classes in the package are managed by Spring; which allows you to scan a package without having to manage all classes in that package.