Download Spring related Jar packages and documents

1. Visit the Spring website

The official website address of Spring is: spring. IO. From the official website, select the following operations to go to the Spring project home page

Project -> Spring Framework 
Copy the code

Version 5.3.16 (GA for stable version) was used for this study review.

2. How do I download the official JAR package

After selecting OVERVIEW, click on the Github icon (🐱) in the upper right corner as shown in the image.Copy the code

Spring’s Github repository: github.com/spring-proj… On the page at this address, find the following: Access to Binaries


For access to artifacts or a distribution zip, see the Spring Framework Artifacts wiki page.

At the bottom of the page you can find the Spring repository address.

Downloading a Distribution


If for whatever reason you are not using a build system with dependency management capabilities, you can download Spring Framework distribution zips from the Spring repository at repo.spring.io. These distributions contain all source and binary jar files, as well as Javadoc and reference documentation, but do not contain external dependencies!

Click the link in 👆 text to enter the warehouse

Copy the picture on the last arrow points to address, and behind the address of the stitching on the spring will be able to direct the warehouse address: repo. Spring. IO/UI/native/r…

Download spring-Framework-5.0.20. release-dist. Zip.

Docs: contains official documentation and API documentation. Libs: contains all jars for Spring

Two, Spring source code environment construction

1. Environment configuration description

  • Spring – 5.0.20 version
  • Gradle 4.4.1
  • JDK1.8
  • The IDEA of 2021.3.2
  • Mac OS
Spring version Gradle version JDK version
Spring – 5.0 x Gradle – 4.4.1 JDK8+
Spring – 5.1 x Gradle – 4.10.3 JDK9+
Spring – 5.2 x Gradle – 5.6.4 JDK11+

Why choose the version? If you choose a higher version of Spring and Gradle is also a higher version, it is better to choose a higher version of JDK because different Gradle versions require different JDK versions to compile. Otherwise, the following errors are prone to occur:

Java: package jdk.jfr does not existCopy the code

2. Download source code

Spring project address: github.com/spring-proj…

Click to download the source package, download to the local after decompressing the name of the file directory

It is slow to download directly on Github for domestic network. You can download the relevant source package from my Gitee project address.

3. Modify the download source

Go to the spring-Framework-project directory and find the build.gradle file, as shown below

repositories {
	mavenCentral()
	maven { url "https://repo.spring.io/libs-spring-framework-build"}}Copy the code

Replace it with ali Cloud warehouse address, Ali cloud warehouse instructions

repositories {
	//mavenCentral()
	//maven { url "https://repo.spring.io/libs-spring-framework-build" }
        maven { url 'https://maven.aliyun.com/repository/public/' }
        maven { url 'https://maven.aliyun.com/repository/spring/'}}Copy the code

4. Gradle installation

The source code of Spring is built on Gradle. Different versions of Spring may use different Gradle versions, so the local installation should also be corresponding to the corresponding Gradle version number, to avoid the late compilation of various unknown problems.

  • The following directory is displayed
cd ~/spring-framework-project/gradle/wrapper
Copy the code
  • Find the gradle-wrapper.properties file and open it
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\:/ / services.gradle.org/distributions/gradle-4.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Copy the code

This file will automatically download Gradle from the configured address after importing the project with IDEA. The distributionUrl in the configuration file is the download address. But IDEA to download may fail, and the speed is not very fast. So we changed the address to local and had him download it from us.

Gradle can be downloaded at gradle.org/releases/

After downloading it, I put it in the local directory ~/Software

  • Replace the distributionUrl address

Local Gradle file location:

/ Users/shifeifei/Software/gradle - 4.4.1 - bin. ZipCopy the code

The distributionUrl configuration on the Mac OS is as follows:

DistributionUrl = file://////Users/shifeifei/Software/gradle-4.4.1-bin.zippCopy the code

Verify that the address configuration is correct

file://////Users/shifeifei/Software/gradle-4.4.1-bin.zip
Copy the code

Enter the file in the browser. If the file can be downloaded, the configured path is correct

5. Import the Spring source project

Before importing Git, ensure that the Git environment is set up, and then open IDEA to prepare for importing Spring source code. Before importing the project, refer to the import-into-idea.md description file in the project directory

## Steps

_Within your locally cloned spring-framework working directory:_

1. Precompile `spring-oxm` with `./gradlew :spring-oxm:compileTestJava`
2. Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle)
3. When prompted exclude the `spring-aspects` module (or after the import via File-> Project Structure -> Modules)
4. Code away
Copy the code

Run the following command before importing

cd ~/Projects/spring-framework-project

./gradlew :spring-oxm:compileTestJava
Copy the code

The command is successfully executed if the following information is displayed

> Task :spring-oxm:genCastor
[ant:javac] : warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

> Task :spring-oxm:genJaxb
[ant:javac] : warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

Download https:/ / maven.aliyun.com/repository/public/org/apache/bcel/bcel/6.0/bcel-6.0.pom
Download https:/ / maven.aliyun.com/repository/public/org/jibx/jibx-bind/1.3.1/jibx-bind-1.3.1.pom
Download https:/ / maven.aliyun.com/repository/public/org/apache/ant/ant/1.8.4/ant-1.8.4.pom
Download https:/ / maven.aliyun.com/repository/public/org/apache/ant/ant-parent/1.8.4/ant-parent-1.8.4.pom
Download https:/ / maven.aliyun.com/repository/public/org/apache/ant/ant-launcher/1.8.4/ant-launcher-1.8.4.pom
Download https:/ / maven.aliyun.com/repository/public/org/jibx/jibx-bind/1.3.1/jibx-bind-1.3.1.jar
Download https:/ / maven.aliyun.com/repository/public/org/apache/ant/ant/1.8.4/ant-1.8.4.jar
Download https:/ / maven.aliyun.com/repository/public/org/apache/ant/ant-launcher/1.8.4/ant-launcher-1.8.4.jar
Download https:/ / maven.aliyun.com/repository/public/org/apache/bcel/bcel/6.0/bcel-6.0.jar

BUILD SUCCESSFUL in 2m 29s
58 actionable tasks: 58 executed
Copy the code

Official import using IDEA!!!!!!!!!

(1) After entering the project, you can see the following prompts

fatal: not a git repository (or any of the parent directories): .git
Copy the code

This is because we are a downloaded zip package, no Git file, let’s execute git initialization command

git init 
Copy the code

(2) Configure the project environment in IDEA

  • The JDK is set
File --> Project Structure 
Copy the code

  • Gradle configuration

  • Compile the source code

Source code compiled successfully!! ✿ ✿ ✿

3. Create a Module

  • Create a spring-Demo-bean test module in IDEA in the following order
File --> New Module --> Gradle
Copy the code

  • Add dependency modules to the Spring-Demo-bean module

Add dependencies in the build.gradle file in the spring-Demo-bean directory

dependencies {

     compile(project(":spring-aop"))
     compile(project(":spring-beans"))
     compile(project(":spring-context"))
     compile(project(":spring-core"))
     compile(project(":spring-context-support"))
     compile(project(":spring-expression"))
     compile(project(":spring-jdbc"))
     compile(project(":spring-tx"))

     testImplementation 'junit: junit: 4.12'
}
Copy the code

Note: It is important to add these dependencies to avoid errors due to lack of dependencies in later test code.

  • If you want to use Web-related functionality, you can add spring-Web related dependencies, depending on your testing

(1) Write test code

  • Defining entity Objects
public class User {

    private String username;

    public String getUsername(a) {
        return username;
    }

    public void setUsername(String username) {
        this.username = username; }}Copy the code
  • Create the resources directory: application-bean.xml


      
<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-3.0.xsd">

    <bean id="user" class="com.sff.demo.bean.User">
        <property name="username" value="Tom"/>
    </bean>
</beans>

Copy the code
  • Write the main method
public class BeanTest {

    public static void main(String[] args) {

        ApplicationContext cx = new ClassPathXmlApplicationContext("application-bean.xml");
        User user = cx.getBean("user", User.class); System.out.printf(user.getUsername()); }}Copy the code
  • The results
objc[43921]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk18.. 0 _111.jdk/Contents/Home/bin/java (0x10e7634c0) and /Library/Java/JavaVirtualMachines/jdk18.. 0 _111.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10f7884e0). One of the two will be used. Which one is undefined. March06.2022 10:19:04Morning org. Springframework. Context. Support. AbstractApplicationContext prepareRefresh information: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5caf905d: startup date [Sun Mar06 10:19:04 CST 2022]; Root of Context Hierarchy March06.2022 10:19:04Morning org. Springframework. Beans. Factory. XML. XmlBeanDefinitionReader loadBeanDefinitions information: Loading XML bean definitions fromclass path resource [application-bean.xml]
Tom
Process finished with exit code 0
Copy the code

(2) Possible problems

  • Kotlin’s version is wrong
Kotlin: Language version 1.1 is no longer supported; please, use version 1.3 or greater.
Copy the code

Check your IDEA for Kotlin plugins:

IntelliJ IDEA --> Preferences --> Plugins --> Kolint
Copy the code

Then go to the build.gradle file and find the following contents:

compileKotlin {
   kotlinOptions {
      jvmTarget = "1.8"
      freeCompilerArgs = ["-Xjsr305=strict"]
      apiVersion = "1.1"
      languageVersion = "1.1"}}Copy the code

I changed the Kotlin version of it

compileKotlin {
   kotlinOptions {
      jvmTarget = "1.8"
      freeCompilerArgs = ["-Xjsr305=strict"]
      apiVersion = "1.3"
      languageVersion = "1.3"}}Copy the code

Write at the end

Teach a man to fish rather than give him fish. Debug source code Gitee