From 1631322676789ef4f1c585d929ec4a42e022a23e Mon Sep 17 00:00:00 2001 From: Yi Siqi Date: Wed, 17 Jul 2024 12:10:16 +0800 Subject: [PATCH] upgrade to java 11 and spring boot 2.7 --- .../CAFUtilsAutoConfiguration.java | 22 +- .../EnvironmentPreparedConfiguration.java | 16 +- caf-boot-parent/pom.xml | 303 ------------------ .../ServletSpringApplicationRunListener.java | 7 +- caf-bootstrap/pom.xml | 4 +- .../java/io/iec/edp/caf/CAFBootstrap.java | 6 +- .../iec/edp/caf/shutdown/ShutDownApiImpl.java | 4 +- pom.xml | 14 +- 8 files changed, 30 insertions(+), 346 deletions(-) diff --git a/caf-boot-autoconfigure/src/main/java/io/iec/edp/caf/autoconfigure/CAFUtilsAutoConfiguration.java b/caf-boot-autoconfigure/src/main/java/io/iec/edp/caf/autoconfigure/CAFUtilsAutoConfiguration.java index 2764eadf..81ae6de8 100644 --- a/caf-boot-autoconfigure/src/main/java/io/iec/edp/caf/autoconfigure/CAFUtilsAutoConfiguration.java +++ b/caf-boot-autoconfigure/src/main/java/io/iec/edp/caf/autoconfigure/CAFUtilsAutoConfiguration.java @@ -19,10 +19,9 @@ package io.iec.edp.caf.autoconfigure; import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; import io.iec.edp.caf.commons.utils.CapEncryptorConfigPostProcessor; -import io.iec.edp.caf.commons.utils.CapLazyEncryptor; import io.iec.edp.caf.commons.utils.CapPropertyPlaceholderConfigurer; import io.iec.edp.caf.commons.utils.SpringBeanUtils; -import lombok.var; +// import lombok.var; import org.jasypt.encryption.pbe.PBEStringEncryptor; import org.jasypt.encryption.pbe.PooledPBEStringEncryptor; import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig; @@ -37,7 +36,6 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.EnvironmentAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Primary; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; @@ -48,9 +46,8 @@ import java.util.Objects; import java.util.Properties; /** - * @author wangyandong - * @date 2019/9/20 16:36 - * @email wangyandong@inspur.com + * @author wangyandong + * @since 0.1.0 */ @Configuration(proxyBeanMethods = false) @EnableEncryptableProperties @@ -60,10 +57,8 @@ public class CAFUtilsAutoConfiguration implements EnvironmentAware, BeanFactoryA private BeanFactory beanFactory; - /** + /* * 加载外部配置文件 - * - * @return */ @Bean @Primary @@ -103,11 +98,8 @@ public class CAFUtilsAutoConfiguration implements EnvironmentAware, BeanFactoryA // return CapLazyEncryptor.getSingleton(environment, beanFactory); // } - /** + /* * 配置读取processor - * - * @param environment - * @return */ @Bean public CapEncryptorConfigPostProcessor capEncryptorConfigPostProcessor(ConfigurableEnvironment environment) { @@ -115,10 +107,8 @@ public class CAFUtilsAutoConfiguration implements EnvironmentAware, BeanFactoryA } - /** + /* * 实现ApplicationContextAware接口的回调方法。设置上下文环境 - * - * @param applicationContext */ @Override public void setApplicationContext(ApplicationContext applicationContext) { diff --git a/caf-boot-autoconfigure/src/main/java/io/iec/edp/caf/autoconfigure/EnvironmentPreparedConfiguration.java b/caf-boot-autoconfigure/src/main/java/io/iec/edp/caf/autoconfigure/EnvironmentPreparedConfiguration.java index fbfe4379..2a29b33b 100644 --- a/caf-boot-autoconfigure/src/main/java/io/iec/edp/caf/autoconfigure/EnvironmentPreparedConfiguration.java +++ b/caf-boot-autoconfigure/src/main/java/io/iec/edp/caf/autoconfigure/EnvironmentPreparedConfiguration.java @@ -22,10 +22,10 @@ import io.iec.edp.caf.commons.runtime.CafEnvironment; import io.iec.edp.caf.commons.utils.JarUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.loader.LaunchedURLClassLoader; -import sun.misc.URLClassPath; import java.io.*; -import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.nio.charset.StandardCharsets; @@ -94,16 +94,14 @@ public class EnvironmentPreparedConfiguration { } private static void addUrl(LaunchedURLClassLoader launchedURLClassLoader, URL[] urls) { - URLClassPath ucp; try { - Field ucpField = URLClassLoader.class.getDeclaredField("ucp"); - ucpField.setAccessible(true); - ucp = (URLClassPath) ucpField.get(launchedURLClassLoader); + Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); + addUrlMethod.setAccessible(true); for (URL url : urls) { - ucp.addURL(url); + addUrlMethod.invoke(launchedURLClassLoader, url); } - } catch (NoSuchFieldException | IllegalAccessException e) { - e.printStackTrace(); + } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { + log.error("Failed add new URL into URLClassLoader.", e); } } diff --git a/caf-boot-parent/pom.xml b/caf-boot-parent/pom.xml index 419de295..16376c96 100644 --- a/caf-boot-parent/pom.xml +++ b/caf-boot-parent/pom.xml @@ -205,309 +205,6 @@ ${caf-framework.version} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/caf-boot-starters/caf-boot-starter-web/src/main/java/io/iec/edp/caf/boot/starter/middleware/config/ServletSpringApplicationRunListener.java b/caf-boot-starters/caf-boot-starter-web/src/main/java/io/iec/edp/caf/boot/starter/middleware/config/ServletSpringApplicationRunListener.java index d3a2474e..b82ebfd4 100644 --- a/caf-boot-starters/caf-boot-starter-web/src/main/java/io/iec/edp/caf/boot/starter/middleware/config/ServletSpringApplicationRunListener.java +++ b/caf-boot-starters/caf-boot-starter-web/src/main/java/io/iec/edp/caf/boot/starter/middleware/config/ServletSpringApplicationRunListener.java @@ -17,21 +17,18 @@ package io.iec.edp.caf.boot.starter.middleware.config; -import io.iec.edp.caf.app.manager.classloader.CAFClassLoader; import io.iec.edp.caf.boot.starter.middleware.spi.utils.ClassLoaderResolverUtils; import io.iec.edp.caf.commons.runtime.CafEnvironment; import io.iec.edp.caf.commons.utils.JarUtil; import lombok.var; +import org.springframework.boot.ConfigurableBootstrapContext; import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplicationRunListener; import org.springframework.context.ApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; -import sun.misc.URLClassPath; -import java.lang.reflect.Field; import java.net.URL; -import java.net.URLClassLoader; import java.nio.file.Path; import java.nio.file.Paths; @@ -52,7 +49,7 @@ public class ServletSpringApplicationRunListener implements SpringApplicationRun * @param environment the environment */ @Override - public void environmentPrepared(ConfigurableEnvironment environment) { + public void environmentPrepared(ConfigurableBootstrapContext bootstrapContext, ConfigurableEnvironment environment) { //当需要配置中心时,此值不为null var loaded = environment.getProperty("caf.config.client"); if (loaded != null) { diff --git a/caf-bootstrap/pom.xml b/caf-bootstrap/pom.xml index 81ff4bf2..8e2820fa 100644 --- a/caf-bootstrap/pom.xml +++ b/caf-bootstrap/pom.xml @@ -84,10 +84,10 @@ jakarta.servlet jakarta.servlet-api - + com.fasterxml.jackson.jaxrs jackson-jaxrs-base diff --git a/caf-bootstrap/src/main/java/io/iec/edp/caf/CAFBootstrap.java b/caf-bootstrap/src/main/java/io/iec/edp/caf/CAFBootstrap.java index 6b9f7684..940a4848 100644 --- a/caf-bootstrap/src/main/java/io/iec/edp/caf/CAFBootstrap.java +++ b/caf-bootstrap/src/main/java/io/iec/edp/caf/CAFBootstrap.java @@ -28,10 +28,11 @@ import io.iec.edp.caf.multicontext.classloader.PlatformClassloader; import io.iec.edp.caf.multicontext.context.PlatformApplicationContext; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import lombok.var; +// import lombok.var; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.boot.ApplicationContextFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -71,7 +72,8 @@ public class CAFBootstrap { if (parallel) { //并行启动 Thread.currentThread().setContextClassLoader(new PlatformClassloader(Thread.currentThread().getContextClassLoader())); - springApplication.setApplicationContextClass(PlatformApplicationContext.class); + springApplication.setApplicationContextFactory(ApplicationContextFactory.ofContextClass(PlatformApplicationContext.class)); + // springApplication.setApplicationContextClass(PlatformApplicationContext.class); } else { //非并行启动 AppManager.enableAppManager(Thread.currentThread()); diff --git a/caf-bootstrap/src/main/java/io/iec/edp/caf/shutdown/ShutDownApiImpl.java b/caf-bootstrap/src/main/java/io/iec/edp/caf/shutdown/ShutDownApiImpl.java index a8daca04..9970c8eb 100644 --- a/caf-bootstrap/src/main/java/io/iec/edp/caf/shutdown/ShutDownApiImpl.java +++ b/caf-bootstrap/src/main/java/io/iec/edp/caf/shutdown/ShutDownApiImpl.java @@ -1,11 +1,9 @@ package io.iec.edp.caf.shutdown; import io.iec.edp.caf.commons.utils.SpringBeanUtils; -import lombok.var; +// import lombok.var; import org.springframework.context.ConfigurableApplicationContext; -import java.util.Map; - public class ShutDownApiImpl implements ShutDownApi { @Override diff --git a/pom.xml b/pom.xml index f063dfb8..1f8c0810 100644 --- a/pom.xml +++ b/pom.xml @@ -30,12 +30,14 @@ UTF-8 UTF-8 - 1.8 - 1.8 - 1.8 - 2.4.13 - 5.3.26 - 1.7.0-beta.1 + 11 + 11 + 11 + + 2.7.18 + 5.3.31 + 2.0.0-beta.1 + https://git.iec.io/caf/caf-boot -- Gitee