Spring foundation (1): Spring+JavaEE structure

1. Spring:
JavaEE's three-tier architecture
web layer: processing user requests and displaying data Representative: Struts2 SpringMVC
service layer: processing business logic Representative: what we need to do
Persistence layer: operating database representative: Hibernate Mybatis

JavaEE architecture diagram:
Insert picture description here

ssh:
Structs2 + Spring + hibernate
ssm;
SpringMVC +Spring + Mybatis
SpringBoot +Mybatis

2. The concept of
Spring Spring is a one-stop lightweight open source framework. Its main function is to reduce the coupling between the service layer and other layers.
High cohesion and low coupling.
3. Spring's core
Spring core is inversion of control (IOC) And Aspect Programming (AOP)
4. Advantages of Spring
1. Convenient decoupling and simplified development.
Through the IoC container provided by Spring, we can control the dependencies between objects to Spring to avoid excessive program coupling caused by hard coding . With Spring, users no longer need to write code for very low-level requirements such as single-instance mode classes and property file analysis, and can focus more on upper-level applications.
Spring is a big factory (container), which can maintain all created objects and dependencies and hand it over to Spring to manage the
Spring factory to produce beans
2. AOP programming support
Through the AOP function provided by Spring, it is convenient for aspect-oriented programming. Many functions that are not easy to implement with traditional OOP can be easily handled by AOP.
3. Support for declarative transactions
In Spring, we can free ourselves from the monotonous and boring transaction management code, and flexibly manage transactions through a declarative way to improve development efficiency and quality.
4. Convenient for program testing
Almost all testing work can be done in a non-container-dependent programming method. In Spring, testing is no longer an expensive operation, but something that can be done at hand. For example: Spring supports Junit4, and Spring programs can be easily tested through annotations.
5. Conveniently integrate various excellent frameworks
Spring does not exclude various excellent open source frameworks. On the contrary, Spring can reduce the difficulty of using various frameworks. Spring provides direct support for various excellent frameworks (such as Struts, Hibernate, Hessian, Quartz), etc.
6. Reduce the difficulty of using Java EE API
Spring provides a thin encapsulation layer for many difficult-to-use Java EE APIs (such as JDBC, JavaMail, remote calls, etc.). Through Spring's simple encapsulation, these Java EE APIs are difficult to use Greatly reduced.
7. Java source code is a classic learning example.
Spring's source code design is exquisite, clear in structure, and original ingenuity. It reflects the master's flexible use of Java design patterns and advanced knowledge of Java technology. The Spring framework source code is undoubtedly a best practice example of Java technology.
If you want to quickly improve your Java technology level and application development level in a short period of time, learning and studying Spring source code will make you receive unexpected results.

5. Spring's structural system
Spring's core container: bean, core, context, spEL
Spring structural system diagram:
Insert picture description here

6. IOC
inversion of control, giving the power to create objects to the Spring container
7. Entry case
Requirements: UserService interface and an implementation class, call the method addEmp()
1. Create project
2. Add dependency
3. Create interface and implementation class
4 . Create Spring container applicationContext.xml
5. Test

8. DI
DI: dependency injection
is a; is a (inheritance)
like a: like a (implementation)
has a: there is a (dependency)
dependent java code embodiment:
Class A { private B b; A depends on B } dependency : One object needs to be used by another object. Injection: Assignment, assigning a value to another pair dependency through setter



Process-oriented-object-oriented-interface-oriented-component-oriented (component)-service-oriented-for Baidu

Guess you like

Origin blog.csdn.net/qq_43479839/article/details/92794422