1. Coding principle of original Tomcat + Servlet



2. Principle of Spring IOC



  • Conclusion:

    • 1. When Tomcat is started, it starts the Spring container

    • 2. The Spring container instantiates bean objects based on XML configuration or annotations, and then performs dependency injection (DEPENDENCY injection) on reference relationships between bean objects based on XML configuration or annotations.

    • The bottom layer uses reflection technology to build objects directly from your class

    • The system implements understanding coupling between classes

3. Spring AOP mechanisms

  • In classes that implement database business code, there are often transactional database logic methods that require transaction management (open, rollback, commit). Spring uses AOP mechanisms (dynamic proxy technology at its core) to manage these repetitive code.

  • Process:

    • Do the plane:

      • In some classes (such as MyserviceXXX class) of all the methods in the woven into the code and began to run in these method, metropolitan area open a transaction, in after all of these methods has been completed, to judge a judgment about whether to throw an exception if an exception is thrown to roll back the transaction, if you don’t have to commit the transaction.

  • Cgclib & JDK dynamic proxy

    • If a class implements an interface, Spring AOP uses JDK dynamic proxies to generate a proxy class that implements the same interface, constructing an instance object.

    • When a class does not implement an interface, Spring AOP uses Cglib to generate a dynamic proxy, which generates a subclass of that class that dynamically generates bytecode, overrides some methods, and enhances them in the method