The role of spring @controller @service @repository @component

1. @controller controller (injecting service)
2. @service service (injecting dao)
3. @repository dao (implementing dao access)
4. @component (instantiating ordinary pojo into the spring container, which is equivalent to the configuration file <bean id="" class=""/>)
  @Component, @Service, @Controller, @Repository annotated classes, and incorporate these classes into the spring container for management.
Write this below to introduce the scanning component of component
<context:component-scan base-package=”com.mmnc”>   

where base-package is the package to be scanned (including all sub-packages)
       1. @Service is used to mark 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, namely DAO components.
       4. @Component refers to components in general. When components are not well classified, we You can use this annotation for annotation.   
           @Service public class UserServiceImpl implements UserService { }
           @Repository public class UserDaoImpl implements UserDao { } The default name of getBean is the class name (initial lowercase), if you want to customize it, you can specify it like @Service("***"), this bean is a singleton by default, If you want to change, you can use @Service("beanName")
           @Scope("prototype") to change. The initialization method and destruction method can be specified in the following way (the method name is arbitrary): @PostConstruct public void init() { }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326530289&siteId=291194637