@ Service annotation, @ Service Annotation
First, add a line in the applicationContext. xml file:
<Context: component-scan base-package = "com. hzhi. clas"/>
After this line is added, the package under the path will be automatically scanned. If a class carries the @ Service annotation, it will be automatically registered to the Spring container and does not need to be in applicationContext. the xml file defines beans. Similar examples include @ Component, @ Repository, and @ Controller.
For example, the following class:
@ Service ("courseDAO") @ Scope ("prototype") public class CourseDAOImpl extends HibernateDaoSupport implements CourseDAO {......}
The function is equivalent to the following in the applicationContext. xml file:
<Bean id = "courseDAO" class = "com. hzhi. course. dao. CourseDAOImpl" scope = "prototype"> ...... </bean>