Concept overview of Spring5
1. Spring is a lightweight open source JavaEE framework
2. Spring can solve the complexity of enterprise application development
spring composition-seven modules
3. Spring has two core parts: IOC and Aop
(1) IOC (Inversion Of Control) : Inversion of control, the process of creating objects is handed over to Spring for management. For example, if there is a class, we want to call a method in the class (not a static method), we must create an object of the class, and use the object call method to achieve it. But for Spring, the process of Spring creating objects is not implemented in the code, but is handed over to Spring for configuration and implementation;
(2) Aop (Aspect Oriented Programming): aspect-oriented, without modifying the source code for functional enhancement
4. Spring features
(1) Convenient decoupling and simplified development
(2) Aop programming support
(3) Convenient program testing
(4) Convenient integration with other frameworks
(5) Convenient transaction operations
(6) Reduce the difficulty of API development
Download Spring5
- Enter Spring official website
2. Click Spring Framework under projects, enter the new page and click the gitHub icon
3. After entering the gitHub page, scroll down to find Access to Binaries , and then click Spring Framework Artifacts
4. After entering the new page, find Downloading a Distribution, and then click https://repo.spring.io
5. After entering the new page, click as shown Icon +
6, find and drop down to find release and click org -> springframework -> spring and click spring
7, copy the address on the right
8. Add the address to the new page at https://repo.spring.io/, select the latest version ( GA+ latest)
Spring5 entry case
The jar package used
creates a common class
package com.atguigu.spring5;
public class User {
private String userName;
public User() {
}
public User(String userName) {
this.userName = userName;
}
public void add() {
System.out.print("add.....");
}
}
Create a Spring configuration file and configure the created object in the configuration file
(1) The Spring configuration file uses xml format
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--配置 User 对象创建-->
<bean id="user" class="com.atguigu.spring5.User"></bean>
</beans>
Write test code
package com.atguigu.spring5.testDemo;
public class TestSpring5 {
@Test
public void testAdd() {
//1 加载 spring 配置文件
ApplicationContext context =
new ClassPathXmlApplicationContext("bean1.xml");
//2 获取配置创建的对象
User user = context.getBean("user", User.class);
System.out.println(user);
user.add();
}
}
The output result
enters spring5 (the next day)