web - @Repository @Service @Controller @Component @Scope

1.  @Repository、@Service、@Controller 和 @Component

     Function: Identify the class as a Bean , saving the process of configuring the XML file  http://blog.csdn.net/ye1992/article/details/19971467

     @Repository - DAO class

     @Service - Server class

     @Controller       - controller类

     @Component - normal class

    The above four bean annotations need to be used with the annotation @Scope("prototype"), which declares the multi-instance mode of this bean, the default singleton mode http://blog.csdn.net/songxingfeng/article/details/7882197

 

2. @Repository("testDao") testDao is the name of the bean. If the spring-managed bean in parentheses is not added, the first letter of the class name is lowercase by default. The
    advantage is that if there are multiple beans of the same type, you can add the name yourself distinguish.
    An interface has multiple implementation classes, because spring injection searches by type by default, just injection will report an error, you add a name to the bean on each implementation class, and add @Qualifier when injecting (the name of the bean you want to inject ) will do

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327054228&siteId=291194637