spring-framework 5.2.x环境搭建
1、获取代码
从github官网 获取找到自己想要的版本下载zip或者,使用git命令
git clone -b 5.2.x https://github.com/spring-projects/spring-framework.git
2、查看所使用的的gradle版本
打开文件spring-framework\gradle\wrapper\gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
# distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
distributionUrl=file:///d:/installPackage/gradle-5.6.4-bin.zip # 改成自己的gradle包位置
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
配置gradle-5.6.4环境变量
配置idea中的gradle
查看拉取目录中的import-into-idea.md文档
配置文件build.gradle,替换为下面内容
pluginManagement {
repositories {
gradlePluginPortal()
// 配置阿里云
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://repo.spring.io/plugins-release' }
}
}
搜素repositories,替换为下面内容
repositories {
新增两条
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" }
}
修改gradle.properties文件
version=5.2.23.BUILD-SNAPSHOT
org.gradle.jvmargs=-Xmx2048M
org.gradle.caching=true
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.daemon=true
在源码的包下执行命令: gradlew :spring-oxm:compileTestJava
编译spring-oxm模块
编译成功后
3、使用idea打开项目,等待项目加载成功,如下图
4、排除某个不需要的模块步骤
5、新增模块
5.1、创建模块
在build.gradle文件中新增一些基本依赖
plugins {
id 'java'
}
group 'org.springframework'
version '5.2.23.BUILD-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
compile(project(":spring-beans"))
compile(project(":spring-core"))
compile(project(":spring-context"))
testCompile group: 'junit', name: 'junit', version: '4.12'
}
创建Class User
package com.demo.myb.dao;
/**
* @Author mengyb
* @description TODO
* @Date 2023/3/13 15:08
* @Version 1.0
*/
public class User {
public void hello() {
System.out.println("hello, spring...");
}
}
创建配置文件spring-config.xml
<?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">
<!--配置Bean: User-->
<bean id="user" class="com.demo.myb.dao.User"/>
</beans>
准备一个测试类
package com.demo.myb;
/**
* @Author mengyb
* @description TODO
* @Date 2023/3/13 15:09
* @Version 1.0
*/
public class MengybDemo {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-config.xml");
User user = (User) applicationContext.getBean("user");
user.hello();
}
}