@component、@RestController

 

@RestController

Remote Call Interface

1, @ controller controller (injection service)

  • Controlling a label layer, a layer corresponding to the struts action

2, @ service service (injection dao)

  • A service logic processing annotation layer, primarily used for service

3, @ repository (dao achieve access)

  • For annotation data access layer, it can be said for the annotation data access components, i.e. DAO components.

4, @ component (the ordinary spring pojo instantiated into the container, corresponding to the configuration file 
<bean id="" class=""/>)

      • (When not belong @ Controller, @ Services, etc.) refers to the various components, that is when our class does not belong to a variety of classification, we can use to label this class @Component

        Here is the introduction of writing this component of the scanning unit 

        1

        <context:component-scan base-package=”com.mmnc”>

         Wherein the base-package package to be scanned (including all sub-packets) 

               1, @ Service label for the business layer assembly 
               2, @ Controller for controlling annotation layer assembly (e.g., the action struts) 
               . 3, for the Repository @ annotation data access components, i.e. DAO components. 
               . 4, @ refers to the Component assembly, when the assembly is not good classification, we can use this annotation to mark.    
                     @Service public class UserServiceImpl implements UserService {}      

                    @Repository public class UserDaoImpl implements UserDao {} getBean default name is the class name (first letter lowercase), if you want to customize, can @Service ( "***") to specify this, this embodiment is a single default bean, If you want to change, you can use @Service ( "beanName") 

                   @Scope ( "prototype") to change. Can be initialized and destruction method (method name any) specified in the following ways: @PostConstruct public void init () {}

Guess you like

Origin www.cnblogs.com/KFKang/p/11162108.html
Recommended