spring-framework-5.3.23 源码编译环境依赖jdk 11
如果网络环境不好可以先下载好:
gradle-7.2-bin.zip
然后下载好:spring-framework-5.3.23 源码
第一步:下载完整后更改:
gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=file:///E:/..../..../gradle/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
第二步:更改build.gradle
build.gradle
中添加:
tasks.named('jar') {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
第三步:更改 settings.gradle
pluginManagement {
repositories {
maven { url "https://maven.aliyun.com/repository/public" }
maven { url "https://maven.aliyun.com/repository/gradle-plugin" }
mavenCentral()
gradlePluginPortal()
maven { url "https://repo.spring.io/release" }
}
}
plugins {
id "com.gradle.enterprise" version "3.10.2"
// id "io.spring.ge.conventions" version "0.0.10"
}
第四步:更改 spring-tx>spring-tx.gradle 注释:
//optional("org.jetbrains.kotlinx:kotlinx-coroutinescoroutines-core")
第五步:更改
CoroutinesUtils 类:
编译时:
public static Publisher<?> invokeSuspendingFunction(Method method, Object target, Object... args) {
KFunction<?> function = Objects.requireNonNull(ReflectJvmMapping.getKotlinFunction(method));
if (method.canAccess(null) && !KCallablesJvm.isAccessible(function)) {
KCallablesJvm.setAccessible(function, true);
}
KClassifier classifier = function.getReturnType().getClassifier();
Mono<Object> mono = MonoKt.mono(Dispatchers.getUnconfined(), (scope, continuation) ->
KCallables.callSuspend(function, getSuspendedFunctionArgs(target, args), continuation))
.filter(result -> !Objects.equals(result, Unit.INSTANCE))
.onErrorMap(InvocationTargetException.class, InvocationTargetException::getTargetException);
if (classifier != null && classifier.equals(JvmClassMappingKt.getKotlinClass(Flow.class))) {
return mono.flatMapMany(CoroutinesUtils::asFlux);
}
return mono;
}
编译好之后可以更改为:
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.core;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Objects;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.CoroutineContext;
import kotlin.jvm.JvmClassMappingKt;
import kotlin.reflect.KClassifier;
import kotlin.reflect.KFunction;
import kotlin.reflect.full.KCallables;
import kotlin.reflect.jvm.KCallablesJvm;
import kotlin.reflect.jvm.ReflectJvmMapping;
import kotlinx.coroutines.BuildersKt;
import kotlinx.coroutines.CoroutineStart;
import kotlinx.coroutines.Deferred;
import kotlinx.coroutines.Dispatchers;
import kotlinx.coroutines.GlobalScope;
import kotlinx.coroutines.flow.Flow;
import kotlinx.coroutines.reactor.MonoKt;
import kotlinx.coroutines.reactor.ReactorFlowKt;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
/**
* Utilities for working with Kotlin Coroutines.
*
* @author Sebastien Deleuze
* @author Phillip Webb
* @since 5.2
*/
public abstract class CoroutinesUtils {
/**
* Convert a {@link Deferred} instance to a {@link Mono}.
*/
public static <T> Mono<T> deferredToMono(Deferred<T> source) {
return MonoKt.mono((CoroutineContext)Dispatchers.getUnconfined(),
(scope, continuation) -> source.await((Continuation<? super T>) continuation));
}
/**
* Convert a {@link Mono} instance to a {@link Deferred}.
*/
public static <T> Deferred<T> monoToDeferred(Mono<T> source) {
return BuildersKt.async(GlobalScope.INSTANCE, (CoroutineContext) Dispatchers.getUnconfined(),
CoroutineStart.DEFAULT,
(scope, continuation) -> MonoKt.awaitSingleOrNull(source, (Continuation<? super T>)continuation));
}
/**
* Invoke a suspending function and converts it to {@link Mono} or
* {@link Flux}.
*/
public static Publisher<?> invokeSuspendingFunction(Method method, Object target, Object... args) {
KFunction<?> function = Objects.requireNonNull(ReflectJvmMapping.getKotlinFunction(method));
if (method.isAccessible() && !KCallablesJvm.isAccessible(function)) {
KCallablesJvm.setAccessible(function, true);
}
KClassifier classifier = function.getReturnType().getClassifier();
Mono<Object> mono = MonoKt.mono((CoroutineContext)Dispatchers.getUnconfined(), (scope, continuation) ->
KCallables.callSuspend(function, getSuspendedFunctionArgs(target, args), continuation))
.filter(result -> !Objects.equals(result, Unit.INSTANCE))
.onErrorMap(InvocationTargetException.class, InvocationTargetException::getTargetException);
if (classifier != null && classifier.equals(JvmClassMappingKt.getKotlinClass(Flow.class))) {
return mono.flatMapMany(CoroutinesUtils::asFlux);
}
return mono;
}
private static Object[] getSuspendedFunctionArgs(Object target, Object... args) {
Object[] functionArgs = new Object[args.length];
functionArgs[0] = target;
System.arraycopy(args, 0, functionArgs, 1, args.length - 1);
return functionArgs;
}
private static Flux<?> asFlux(Object flow) {
return ReactorFlowKt.asFlux(((Flow<?>) flow));
}
}