Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Download the source code

First go to GitHub to download the source code. Download: github.com/spring-proj… Note that if you feel that the download is slow, you can first synchronize to your own Gitee warehouse to download, below is the address of my Gitee warehouse gitee.com/zhengsh/spr…

Configuration information

Environmental information:

  • The idea of 2021.2
  • jdk 11
  • Gradle – 6.9.1

Note: try to keep the information consistent with my environment, otherwise it may cause compilation failures or some strange problems when importing the project

Import the project

After importing the project, there is a long wait for compilation and finally loading, as shown below (there is one in the source directory root)import-into-idea.mdThere are also import instructions, you can also refer to this implementation) :

Example Modify the address of a mirror warehouse

By default, the spring repository is used to download the source code. Due to network limitations, it is recommended to configure the image repository provided by Ali in China to download the source code in build.gradle

Repositories {/ / add the following two ali cloud image maven {url 'https://maven.aliyun.com/nexus/content/groups/public/'} maven {url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' } mavenCentral() maven { url "https://repo.spring.io/libs-spring-framework-build" } maven { url "https://repo.spring.io/milestone" } // Reactor / / new spring plug-in library maven {url "https://repo.spring.io/plugins-release"}}Copy the code

Precompiled spring oxm. –

Run./gradlew :spring-oxm:compileTestJava

Import the project

Idea select File -> open -> select source directory -> click openThe dialog box selection is displayed againopen as project. The follow-up is a long wait, the specific time depends on your computer, as well as the speed of the download.

The test case

Create a module

You can create a test module,summer-test

Add the dependent

Then add the dependency in build.gradle

dependencies {
    compile(project(":spring-core"))
    compile(project(":spring-aop"))
    compile(project(":spring-beans"))
    compile(project(":spring-context"))
}
Copy the code

The test code

Finally, add the test code

public class BeanTest {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext applicationContext = newAnnotationConfigApplicationContext(AppConfig.class); UserService serviceService = applicationContext.getBean(UserService.class); System.out.println(serviceService); }}// AppConfig.java
@Configurable
public class AppConfig {

	@Bean
	private UserService user(a) {
		return newUserService(); }}// UserService.java
public class UserService {}Copy the code

The reference information

  • spring.io