spring-framework 5.2.x环境搭建

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打开项目,等待项目加载成功,如下图

https://mengyb-user.oss-cn-beijing.aliyuncs.com/2023/03/13/202303130644129611.jpg

4、排除某个不需要的模块步骤

排除不需要模块的步骤

5、新增模块

5.1、创建模块

创建模块1

创建模块2

在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();
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值