Spring 6.0 源码编译
下载 Spring framework 6.0.0 源码
设置gradle版本
从spring framework 6.0.0/gradle/wrapper/gradle-wrapper.properties
下载对应的gradle版本
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
下载对应的gradle版本,放入到指定目录,设置sha256(sha256也可不设置)
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
# distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=file\:///D:/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=f6b8596b10cce501591e92f229816aa4046424f3b24d771751b06779d58c8ec4
设置依赖库
修改文件 spring framework 6.0.0/settings.gradle
增加 aliyun 依赖地址
pluginManagement {
repositories {
maven { url "https://maven.aliyun.com/repository/central" }
mavenCentral()
gradlePluginPortal()
maven { url "https://repo.spring.io/release" }
}
}
下载jdk17 同时确认idea支持jdk17版本
导入到idea中
idea 打开 spring framework 6.0.0 目录
加载比较耗时 (但比以往Spring4, Spring5 好,一次加载及编译成功)
引入aspectj
不用移除 spring-aspects
模块
新建 gradle 工程
引入相关依赖
spring-context
, aspectjweaver
plugins {
id 'java-library'
}
//task wrapper(type: Wrapper){
// gradleVersion = '7.5.1'
//}
//
//task prepareKotlinBuildScriptModel {
//}
group 'pr.iceworld.fernando'
version '6.0.0'
repositories {
maven { url "https://maven.aliyun.com/repository/central" }
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
api(project(":spring-context"))
implementation 'org.aspectj:aspectjweaver:1.9.9.1'
}
test {
useJUnitPlatform()
}
编码验证搭建是否成功
package pr.iceworld.fernando.spring6.demo.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@ComponentScan("pr.iceworld.fernando.spring6.demo.**")
@EnableAspectJAutoProxy
@Configuration
public class ProjectConfig {
}
package pr.iceworld.fernando.spring6.demo.component;
import org.springframework.stereotype.Component;
@Component
public class MyClass {
public void doAction() {
System.out.println("it's my class");
}
}
package pr.iceworld.fernando.spring6.demo.component;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class AspectSomeClassMethod {
@Pointcut("execution(* pr.iceworld.fernando.spring6.demo.component.MyClass.*(..))")
public void pointMethod() {
}
@Before("pointMethod()")
public void before() {
System.out.println("before action");
}
}
package pr.iceworld.fernando.spring6.demo;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import pr.iceworld.fernando.spring6.demo.component.MyClass;
import pr.iceworld.fernando.spring6.demo.config.ProjectConfig;
public class MainApp {
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(ProjectConfig.class);
MyClass cd = context.getBean(MyClass.class);
cd.doAction();
}
}