Spring @ component: spring @ component
Spring @ component
1. @ controller (injection Service)
2. @ service (inject dao)
3. @ repository dao (implementing dao access)
4. @ component (instantiating a common pojo to a spring container is equivalent to <bean id = "" class = ""/> in the configuration file)
@ Component, @ Service, @ Controller, @ Repository annotation class, and add these classes to the spring container for management.
Below is the scanning component that introduces component.
<context:component-scan base-package=”com.mmnc”>
Base-package indicates the package to be scanned (including all sub-packages)
1. @ Service is used to mark Service layer components
2. @ Controller is used to mark control layer components (such as actions in struts)
3. @ Repository is used to mark the data access component, that is, the DAO component.
4. @ Component refers to a Component. When the Component is difficult to classify, we 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 (the first letter is lower case). to customize it, @ Service ("***") in this way, this bean is a singleton by default. If you want to change it, you can use @ Service ("beanName ")
@ Scope ("prototype") to change. You can use the following method to specify the initialization method and destruction method (the method name is arbitrary): @ PostConstruct public void init (){}
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!