diff --git a/pom.xml b/pom.xml
index c715765c02f61c6d1161020fce158564bba6115c..0970aa19b590cfb7a29c6397b463736fc7a26190 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,7 +13,7 @@
com.gitee.starblues
spring-brick-parent
pom
- 3.0.2
+ 3.0.3
spring-brick-common
diff --git a/spring-brick-bootstrap/pom.xml b/spring-brick-bootstrap/pom.xml
index 730adc0fc110be1b5e129d048858d46bf3b76dfb..cf32d07c87bc0dc4ffc13fbc594c07a843896f0b 100644
--- a/spring-brick-bootstrap/pom.xml
+++ b/spring-brick-bootstrap/pom.xml
@@ -7,7 +7,7 @@
spring-brick-parent
com.gitee.starblues
- 3.0.2
+ 3.0.3
spring-brick-bootstrap
diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/AutowiredTypeDefinerConfig.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/AutowiredTypeDefinerConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..2481c0b13d52707841487cbd9432874bbeac31ea
--- /dev/null
+++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/AutowiredTypeDefinerConfig.java
@@ -0,0 +1,58 @@
+/**
+ * Copyright [2019-2022] [starBlues]
+ *
+ * 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
+ *
+ * http://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 com.gitee.starblues.bootstrap;
+
+import com.gitee.starblues.bootstrap.annotation.AutowiredType;
+import com.gitee.starblues.bootstrap.realize.AutowiredTypeDefiner;
+import com.gitee.starblues.utils.ObjectUtils;
+
+import java.util.*;
+
+/**
+ * 配置 ClassDefiner
+ *
+ * @author starBlues
+ * @since 3.0.3
+ * @version 3.0.3
+ */
+public class AutowiredTypeDefinerConfig {
+
+ private final Set classDefiners;
+
+ public AutowiredTypeDefinerConfig(){
+ this.classDefiners = new HashSet<>();
+ }
+
+ Set getClassDefiners(){
+ return classDefiners;
+ }
+
+ public AutowiredTypeDefinerConfig add(AutowiredType.Type type, String... classNamePatterns){
+ if(type != null && classNamePatterns != null && classNamePatterns.length > 0){
+ classDefiners.add(AutowiredTypeDefiner.ClassDefiner.config(type, classNamePatterns));
+ }
+ return this;
+ }
+
+ public AutowiredTypeDefinerConfig add(AutowiredType.Type type, Class>... classes){
+ if(type != null && classes != null && classes.length > 0){
+ classDefiners.add(AutowiredTypeDefiner.ClassDefiner.config(type, classes));
+ }
+ return this;
+ }
+
+}
diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/AutowiredTypeResolver.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/AutowiredTypeResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..cdbf3454fd4b0eb504eeccb16840c68075005ae1
--- /dev/null
+++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/AutowiredTypeResolver.java
@@ -0,0 +1,73 @@
+/**
+ * Copyright [2019-2022] [starBlues]
+ *
+ * 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
+ *
+ * http://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 com.gitee.starblues.bootstrap;
+
+import com.gitee.starblues.bootstrap.annotation.AutowiredType;
+import com.gitee.starblues.bootstrap.processor.ProcessorContext;
+import com.gitee.starblues.bootstrap.realize.AutowiredTypeDefiner;
+import com.gitee.starblues.utils.ObjectUtils;
+import com.gitee.starblues.utils.UrlUtils;
+import org.springframework.beans.factory.config.DependencyDescriptor;
+import org.springframework.util.AntPathMatcher;
+import org.springframework.util.PathMatcher;
+
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * @author starBlues
+ * @since 3.0.3
+ * @version 3.0.3
+ */
+public class AutowiredTypeResolver {
+
+ private final Set classDefiners;
+ private final PathMatcher pathMatcher = new AntPathMatcher();
+
+
+ public AutowiredTypeResolver(ProcessorContext processorContext) {
+ AutowiredTypeDefiner autowiredTypeDefiner = processorContext.getSpringPluginBootstrap().autowiredTypeDefiner();
+ if(autowiredTypeDefiner != null){
+ AutowiredTypeDefinerConfig definerConfig = new AutowiredTypeDefinerConfig();
+ autowiredTypeDefiner.config(definerConfig);
+ classDefiners = definerConfig.getClassDefiners();
+ } else {
+ classDefiners = Collections.emptySet();
+ }
+ }
+
+ public AutowiredType.Type resolve(DependencyDescriptor descriptor){
+ String name = descriptor.getDependencyType().getName();
+ String classNamePath = UrlUtils.formatMatchUrl(name);
+ for (AutowiredTypeDefiner.ClassDefiner classDefiner : classDefiners) {
+ Set classNamePatterns = classDefiner.getClassNamePatterns();
+ for (String classNamePattern : classNamePatterns) {
+ if(pathMatcher.match(classNamePattern, classNamePath)){
+ return classDefiner.getAutowiredType();
+ }
+ }
+ }
+ AutowiredType autowiredType = descriptor.getAnnotation(AutowiredType.class);
+ if(autowiredType != null){
+ return autowiredType.value();
+ } else {
+ return AutowiredType.Type.PLUGIN;
+ }
+ }
+
+
+}
diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigureMainPluginEnvironment.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigureMainPluginEnvironment.java
index c2e0080564535f9d08d943077d88ce6882844b22..912f2546cda5c555de6622fedaf650c596209b32 100644
--- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigureMainPluginEnvironment.java
+++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigureMainPluginEnvironment.java
@@ -39,6 +39,7 @@ import java.util.*;
* 插件环境配置
* @author starBlues
* @version 3.0.0
+ * @since 3.0.0
*/
class ConfigureMainPluginEnvironment {
diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigurePluginEnvironment.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigurePluginEnvironment.java
index c159c6e9b470648b34f8885e72c18d9f2c539328..67ba59416d5028bf0648ee32f14b546f416fd5e6 100644
--- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigurePluginEnvironment.java
+++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigurePluginEnvironment.java
@@ -23,6 +23,7 @@ import com.gitee.starblues.utils.Assert;
import com.gitee.starblues.utils.FilesUtils;
import com.gitee.starblues.utils.ObjectUtils;
import com.gitee.starblues.utils.PluginFileUtils;
+import org.springframework.context.support.LiveBeansView;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/EmptyMainApplicationContext.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/EmptyMainApplicationContext.java
index 0321276c98ebb22c5e19fe62a551f7e2ff7018af..7608046cae2e2f9f2d41522922e8c80dcb2d4026 100644
--- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/EmptyMainApplicationContext.java
+++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/EmptyMainApplicationContext.java
@@ -18,6 +18,9 @@ package com.gitee.starblues.bootstrap;
import com.gitee.starblues.spring.MainApplicationContext;
import com.gitee.starblues.spring.SpringBeanFactory;
+import com.gitee.starblues.spring.environment.EmptyEnvironmentProvider;
+import com.gitee.starblues.spring.environment.EnvironmentProvider;
+
import java.util.Collections;
import java.util.Map;
import java.util.Set;
@@ -25,7 +28,7 @@ import java.util.Set;
/**
* 空的MainApplicationContext实现
* @author starBlues
- * @version 3.0.1
+ * @version 3.0.3
*/
public class EmptyMainApplicationContext implements MainApplicationContext {
@@ -46,4 +49,19 @@ public class EmptyMainApplicationContext implements MainApplicationContext {
return Collections.emptyMap();
}
+ @Override
+ public EnvironmentProvider getEnvironmentProvider() {
+ return new EmptyEnvironmentProvider();
+ }
+
+ @Override
+ public Object resolveDependency(String requestingBeanName, Class> dependencyType) {
+ return null;
+ }
+
+ @Override
+ public boolean isWebEnvironment() {
+ return false;
+ }
+
}
diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginApplicationContext.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginApplicationContext.java
index 2ed37d010bff52beae6cdfe2b5745d590b5a3e35..b6c9cb144c2c80fdad11572076ff3854c6235e9c 100644
--- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginApplicationContext.java
+++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginApplicationContext.java
@@ -20,12 +20,14 @@ import com.gitee.starblues.bootstrap.processor.ProcessorContext;
import com.gitee.starblues.core.descriptor.PluginDescriptor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.boot.web.context.WebServerApplicationContext;
+import org.springframework.boot.web.server.WebServer;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
* 插件ApplicationContext实现
* @author starBlues
- * @version 3.0.0
+ * @version 3.0.3
*/
public class PluginApplicationContext extends AnnotationConfigApplicationContext {
@@ -57,4 +59,5 @@ public class PluginApplicationContext extends AnnotationConfigApplicationContext
public void close() {
super.close();
}
+
}
diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginContextHolder.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginContextHolder.java
new file mode 100644
index 0000000000000000000000000000000000000000..253c89496778d88012cf4cead27aa891c9267d5d
--- /dev/null
+++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginContextHolder.java
@@ -0,0 +1,121 @@
+/**
+ * Copyright [2019-2022] [starBlues]
+ *
+ * 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
+ *
+ * http://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 com.gitee.starblues.bootstrap;
+
+import com.gitee.starblues.bootstrap.processor.ProcessorContext;
+import com.gitee.starblues.core.descriptor.InsidePluginDescriptor;
+import com.gitee.starblues.integration.IntegrationConfiguration;
+import com.gitee.starblues.spring.SpringBeanFactory;
+import com.gitee.starblues.spring.environment.EnvironmentProvider;
+
+/**
+ * 提供插件上下文的工具类
+ *
+ * @author starBlues
+ * @version 3.0.3
+ */
+public abstract class PluginContextHolder {
+
+ private static volatile Boolean INITIALIZED = false;
+
+ private static ProcessorContext processorContext;
+
+ private static ClassLoader pluginClassLoader;
+ private static InsidePluginDescriptor pluginDescriptor;
+
+ private static IntegrationConfiguration configuration;
+ private static Boolean mainIsWebEnv;
+ private static SpringBeanFactory mainSpringBeanFactory;
+
+
+ private PluginContextHolder(){}
+
+ static void initialize(ProcessorContext processorContext){
+ if(INITIALIZED){
+ return;
+ }
+ PluginContextHolder.processorContext = processorContext;
+
+ PluginContextHolder.pluginClassLoader = processorContext.getClassLoader();
+ PluginContextHolder.pluginDescriptor = processorContext.getPluginDescriptor();
+ PluginContextHolder.configuration = processorContext.getConfiguration();
+ PluginContextHolder.mainIsWebEnv = processorContext.getMainApplicationContext().isWebEnvironment();
+ PluginContextHolder.mainSpringBeanFactory = processorContext.getMainBeanFactory();
+ INITIALIZED = true;
+ }
+
+ /**
+ * 获取主程序环境中配置文件内容提供者
+ * @return EnvironmentProvider
+ */
+ public static EnvironmentProvider getEnvironmentProvider(){
+ check();
+ return processorContext.getMainApplicationContext().getEnvironmentProvider();
+ }
+
+ /**
+ * 获取主程序针对本框架的配置内容
+ * @return IntegrationConfiguration
+ */
+ public static IntegrationConfiguration getConfiguration() {
+ check();
+ return configuration;
+ }
+
+ /**
+ * 获取主程序的 SpringBeanFactory . 通过它可获取主程序中的Bean
+ * @return SpringBeanFactory
+ */
+ public static SpringBeanFactory getMainSpringBeanFactory() {
+ check();
+ return mainSpringBeanFactory;
+ }
+
+ /**
+ * 判断主程序是否为web环境
+ * @return Boolean
+ */
+ public static Boolean getMainIsWebEnv() {
+ check();
+ return mainIsWebEnv;
+ }
+
+ /**
+ * 获取插件的 classloader
+ * @return ClassLoader
+ */
+ public static ClassLoader getPluginClassLoader() {
+ check();
+ return pluginClassLoader;
+ }
+
+ /**
+ * 获取插件信息
+ * @return InsidePluginDescriptor
+ */
+ public static InsidePluginDescriptor getPluginDescriptor() {
+ check();
+ return pluginDescriptor;
+ }
+
+ private static void check(){
+ if(!INITIALIZED){
+ throw new IllegalStateException("PluginContextHolder 未初始化");
+ }
+ }
+
+}
diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginDisableAutoConfiguration.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginDisableAutoConfiguration.java
new file mode 100644
index 0000000000000000000000000000000000000000..7c69c391c44890ee45e68ad11c41df9d666c38af
--- /dev/null
+++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginDisableAutoConfiguration.java
@@ -0,0 +1,72 @@
+/**
+ * Copyright [2019-2022] [starBlues]
+ *
+ * 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
+ *
+ * http://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 com.gitee.starblues.bootstrap;
+
+import com.gitee.starblues.utils.ObjectUtils;
+import org.springframework.boot.autoconfigure.AutoConfigurationImportFilter;
+import org.springframework.boot.autoconfigure.AutoConfigurationMetadata;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 插件禁用的 AutoConfiguration
+ *
+ * @author starBlues
+ * @version 3.0.3
+ */
+public class PluginDisableAutoConfiguration implements AutoConfigurationImportFilter {
+
+ private static final List DISABLE_FUZZY_CLASSES = new ArrayList<>();
+
+ public PluginDisableAutoConfiguration(){
+ addDisableFuzzyClasses();
+ }
+
+ private void addDisableFuzzyClasses() {
+ DISABLE_FUZZY_CLASSES.add("org.springframework.boot.autoconfigure.http");
+ DISABLE_FUZZY_CLASSES.add("org.springframework.boot.autoconfigure.web");
+ DISABLE_FUZZY_CLASSES.add("org.springframework.boot.autoconfigure.websocket");
+ DISABLE_FUZZY_CLASSES.add("org.springframework.boot.autoconfigure.jackson");
+ DISABLE_FUZZY_CLASSES.add("org.springframework.boot.autoconfigure.webservices");
+ }
+
+ public static boolean isDisabled(String className){
+ if(ObjectUtils.isEmpty(className)){
+ return false;
+ }
+ for (String disableFuzzyClass : DISABLE_FUZZY_CLASSES) {
+ if (className.contains(disableFuzzyClass)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean[] match(String[] autoConfigurationClasses, AutoConfigurationMetadata autoConfigurationMetadata) {
+ boolean[] match = new boolean[autoConfigurationClasses.length];
+ for (int i = 0; i < autoConfigurationClasses.length; i++) {
+ String autoConfigurationClass = autoConfigurationClasses[i];
+ if(autoConfigurationClass == null || "".equals(autoConfigurationClass)){
+ continue;
+ }
+ match[i] = !isDisabled(autoConfigurationClass);
+ }
+ return match;
+ }
+}
diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginListableBeanFactory.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginListableBeanFactory.java
index fda812953dfe96df79455ce6c412c62db5e3777f..76e8f7f9917a145fb89fb57aab44c20a46d11ebc 100644
--- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginListableBeanFactory.java
+++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginListableBeanFactory.java
@@ -16,62 +16,95 @@
package com.gitee.starblues.bootstrap;
+import com.gitee.starblues.bootstrap.annotation.AutowiredType;
+import com.gitee.starblues.bootstrap.processor.ProcessorContext;
import com.gitee.starblues.bootstrap.utils.DestroyUtils;
import com.gitee.starblues.spring.MainApplicationContext;
import com.gitee.starblues.spring.SpringBeanFactory;
-import com.gitee.starblues.utils.ObjectUtils;
import com.gitee.starblues.utils.ReflectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.TypeConverter;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.beans.factory.ObjectFactory;
+import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.DependencyDescriptor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.lang.Nullable;
-import java.util.Set;
+import java.util.*;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* 插件BeanFactory实现
* @author starBlues
- * @version 3.0.0
+ * @since 3.0.3
+ * @version 3.0.3
*/
public class PluginListableBeanFactory extends DefaultListableBeanFactory {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
+ private static final Logger LOG = LoggerFactory.getLogger(PluginListableBeanFactory.class);
private final MainApplicationContext applicationContext;
+ private final AutowiredTypeResolver autowiredTypeResolver;
- public PluginListableBeanFactory(MainApplicationContext applicationContext) {
- this.applicationContext = applicationContext;
+ public PluginListableBeanFactory(ProcessorContext processorContext) {
+ this.applicationContext = processorContext.getMainApplicationContext();
+ this.autowiredTypeResolver = new AutowiredTypeResolver(processorContext);
}
+ @SuppressWarnings("unchecked")
@Override
public Object resolveDependency(DependencyDescriptor descriptor,
@Nullable String requestingBeanName,
@Nullable Set autowiredBeanNames,
@Nullable TypeConverter typeConverter) throws BeansException {
-
- try {
- return super.resolveDependency(descriptor, requestingBeanName, autowiredBeanNames, typeConverter);
- } catch (BeansException e){
- return resolveDependencyFromMain(descriptor);
+ AutowiredType.Type autowiredType = getAutowiredType(descriptor);
+ Class> dependencyType = descriptor.getDependencyType();
+ if (dependencyType == ObjectFactory.class || dependencyType == ObjectProvider.class) {
+ Object dependencyObj = super.resolveDependency(descriptor, requestingBeanName, autowiredBeanNames,
+ typeConverter);
+ ObjectProvider