Java framework learning (1)-Spring framework configuration

Posted May 25, 20202 min read

What is the spring framework

Spring is a lightweight Java development framework

The core of the Spring framework

IOC control inversion

In the traditional Java development process, developers actively create objects within the object through the new keyword, and the program actively depends on the objects. In IOC, the creation process of the objects is handed over to the spring container management, and the container completes the creation of objects jobs.

DI dependency injection

The container dynamically injects a certain dependency into the component, that is, the container dynamically provides the external resources(objects, resources, constant data) it needs to an object

AOP for aspect-oriented programming

In the aspect-oriented programming ideas, the functions are also divided into core business functions and peripheral functions
Core business:login, data CRUD
Peripheral business:performance statistics, logs, transaction management
In the idea of aspect-oriented programming AOP, the core business function and the aspect function are independently developed, and then the aspect function and the core business function are "woven" together

Spring framework configuration

Create a project:

  1. Create a maven project

  2. Add project dependency Spring-context

    org.springframework spring-context 4.3.9.RELEASE
  3. Add junit dependency

    junit junit 4.12
  4. Add a configuration file

    <beans xmlns = ""
    xmlns:xsi = ""
    xsi:schemaLocation = " ">

  5. Test class

    public class TestSpring {
    protected ApplicationContext context;
    public void init() {
    context = new ClassPathXmlApplicationContext("applicationContext.xml");
    public void testCtx() {