Spring 6.0 源码编译

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();
	}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值