编程知识 cdmana.com

Learning summary of spring framework

One ,spring frame

      1, It's a very powerful framework , It's a lightweight , Open source framework ,

                Core functions :IOC ( Dependency injection ) 

                                  IOC effect : decoupling , Reducing classes and classes , Methods and dependencies between methods  

                                  In a word, understand :  take  ControllerServiceDao  Components such as   establish   and   The destruction   hand Spring Container to manage , Unwanted Manual  new  object                          

                                 AOP( Section oriented programming )

                                  The proxy pattern :

                                                      The director ——》 actor

                                                    The director ——》 agent ——》 actor

                                  In a word, understand : Through dynamic agents , Without changing the source code , Add extra functionality before and after methods

       2, advantage : Easy decoupling , Reduce coupling ( Compile time does not depend on , The runtime depends on )  

Two , establish spring  IOC Project based on xml When developing

            1, The principle of project operation :

                   spring After the container starts , according to spring.xml Configuration in , take  bean  In the label  id attribute and bean object Put in In the container

                  When use , according to  id  Get the object

                             2,  IOC The underlying operating principle uses the reflection mechanism

                          3, stay bean Add... To the label scope Properties can switch singleton and multiinstance modes

 singleton: The singleton pattern , The default is singleton mode , Objects in singleton mode follow spring The destruction of the container , But if spring The container has always been , Then objects in this mode will always exist

prototype: Many cases of pattern , Every time you use an object, a new object is created , Only this object is being used , It's always been there . When not using this object , Will be Java Garbage collection mechanism for recycling .

                             4, The process of dependency injection , Same as above xml in bean label id and Main The main methods correspond to each other

 

3、 ... and ,spring frame IOC Notes

                1, Use annotations first, and you don't use them anymore xml file ,xml The file is replaced by a configuration class , There are two notes , Function and xml The profile is the same , This class generally uses ‘ApplicationConfig’, Named after the .

 

                2, The function and usage of various annotations :

@Controller: stay   Control layer   Used in . Use in web In the project , The equivalent of an enhanced version of servlet, Receiving request , Return response

@Service: stay  service layer   Used in

@Repository: stay  dao layer   Used in

@Component: above 3 All annotations inherit  @Component  annotation  : This annotation does not belong to   Control layer service layer dao layer , But I want you to spring Container to manage the class , You can use it  @Component  annotation

The same place : There are value attribute , amount to bean Labeled id, If the variable name is not specified , The default is the class name of this class , Initial lowercase

It can be mixed up , But it is not recommended. , How to write , nothing can be accomplished without norms and standards

 

@Autowired : Usage method :

  • On member variables  
  • On the method

effect : Injected object , By default, inject according to the type

@Qualifier : And @Autowired Use it with , You can specify id Injected object

 

@Resource : Instead of the two notes above ,

difference :@Resource By default, inject by name first ; Then match the injection by type

            @Qualifier : And @Autowired yes : By default, inject by type first . If necessary according to id Inject , Need to match  @Qualifier

@Scope  Annotation equivalent  bean  In the tag  scope  attribute , Used to specify the scope of action  : Singleton mode can be switched / Many cases of pattern

Four ,spring frame Aop Development

                                             AOP( Section oriented programming )

                                              In a word, understand : Through dynamic agents , Without changing the source code , Add extra functionality before and after methods

                    

5、 ... and ,

6、 ... and

7、 ... and

8、 ... and

Nine

Ten

版权声明
本文为[Yao Qing]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/01/20210131190248339c.html

Scroll to Top