@component (Instantiate ordinary pojo into the spring container, which is equivalent to
General Refers to various components, that is to say, when our class does not belong to various classifications (when it does not belong to @Controller, @Services, etc.), we can use @Component to annotate this class.
Written below is the scanning component that introduces component
<context:component-scan base-package=”com.mmnc”>
where base-package is the package that needs to be scanned (including all sub-packages)
1. @Service is used to label business layer components
2. @Controller is used to label control layer components (such as actions in struts)
3. @Repository is used to label data access components, that is, DAO components.
4. @Component generally refers to components. When components are difficult to classify, we can use this annotation for annotation.
@Service Public Class UserService Implements UserService {}
@RePOSITORY PUBLIC Class UserDao ImpleMents UserDao {} Getbean The default name is a class name (head letter). If you want to customize, you can @Service ("" " ***”) Specified in this way, this bean is singleton by default. If you want to change it, you can use @Service(“beanName”)
@Scope(“prototype”) to change it. You can use the following methods to specify the initialization method and destruction method (the method name is arbitrary): @PostConstruct public void init() { }
The above is the detailed content of What layer annotation does component have?. For more information, please follow other related articles on the PHP Chinese website!