Commit 5c3e0dd9 authored by liaozan's avatar liaozan 🏀

Reorder dependencies

parent 37664e38
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
<groupId>com.schbrain.common</groupId> <groupId>com.schbrain.common</groupId>
<artifactId>common</artifactId> <artifactId>common</artifactId>
</dependency> </dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</dependency>
<dependency> <dependency>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
......
This diff is collapsed.
...@@ -2,37 +2,31 @@ package com.schbrain.framework.autoconfigure.apollo.listener; ...@@ -2,37 +2,31 @@ package com.schbrain.framework.autoconfigure.apollo.listener;
import com.schbrain.common.util.support.ConfigurableProperties; import com.schbrain.common.util.support.ConfigurableProperties;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.springframework.core.ResolvableType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
/** /**
* @author liaozan * @author liaozan
* @since 2023-04-28 * @since 2023-04-28
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class PropertiesPreparedEventListenerAdapter<T extends ConfigurableProperties> implements PropertiesPreparedEventListener { public abstract class GenericPropertiesPreparedEventListener<T extends ConfigurableProperties> implements PropertiesPreparedEventListener {
private final Class<T> propertyType; protected final ResolvableType propertiesType;
protected Log log; protected Log log;
public PropertiesPreparedEventListenerAdapter() { public GenericPropertiesPreparedEventListener() {
ParameterizedType parameterizedType = (ParameterizedType) getClass().getGenericSuperclass(); this.propertiesType = ResolvableType.forInstance(this).getSuperType().getGeneric(0);
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
this.propertyType = (Class<T>) actualTypeArguments[0];
} }
@Override @Override
public void onApplicationEvent(PropertiesPreparedEvent event) { public void onApplicationEvent(PropertiesPreparedEvent event) {
if (event.getConfigurableProperties().getClass() == propertyType) { if (propertiesType.isInstance(event.getConfigurableProperties())) {
this.log = event.getDeferredLogFactory().getLog(this.getClass()); this.log = event.getDeferredLogFactory().getLog(getClass());
this.onPropertiesPrepared(event, (T) event.getConfigurableProperties()); this.onPropertiesPrepared(event, (T) event.getConfigurableProperties());
} }
} }
protected void onPropertiesPrepared(PropertiesPreparedEvent event, T configurableProperties) { protected abstract void onPropertiesPrepared(PropertiesPreparedEvent event, T configurableProperties);
}
} }
\ No newline at end of file
package com.schbrain.framework.autoconfigure.apollo.listener; package com.schbrain.framework.autoconfigure.apollo.listener;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;
/** /**
* @author liaozan * @author liaozan
* @since 2023-04-29 * @since 2023-04-29
*/ */
public interface PropertiesPreparedEventListener extends ApplicationListener<PropertiesPreparedEvent> { public interface PropertiesPreparedEventListener extends ApplicationListener<PropertiesPreparedEvent>, Ordered {
@Override
default int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
}
} }
\ No newline at end of file
...@@ -3,13 +3,14 @@ package com.schbrain.framework.autoconfigure.dubbo.listener; ...@@ -3,13 +3,14 @@ package com.schbrain.framework.autoconfigure.dubbo.listener;
import com.alibaba.fastjson2.JSONFactory; import com.alibaba.fastjson2.JSONFactory;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.schbrain.common.util.ApplicationName; import com.schbrain.common.util.ApplicationName;
import com.schbrain.framework.autoconfigure.apollo.listener.GenericPropertiesPreparedEventListener;
import com.schbrain.framework.autoconfigure.apollo.listener.PropertiesPreparedEvent; import com.schbrain.framework.autoconfigure.apollo.listener.PropertiesPreparedEvent;
import com.schbrain.framework.autoconfigure.apollo.listener.PropertiesPreparedEventListenerAdapter;
import com.schbrain.framework.autoconfigure.dubbo.properties.DubboProperties; import com.schbrain.framework.autoconfigure.dubbo.properties.DubboProperties;
import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.spring.ConfigCenterBean; import org.apache.dubbo.config.spring.ConfigCenterBean;
import org.apache.dubbo.config.spring.util.EnvironmentUtils; import org.apache.dubbo.config.spring.util.EnvironmentUtils;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import java.util.Map; import java.util.Map;
...@@ -21,10 +22,15 @@ import static org.apache.dubbo.config.ConfigKeys.DUBBO_SCAN_BASE_PACKAGES; ...@@ -21,10 +22,15 @@ import static org.apache.dubbo.config.ConfigKeys.DUBBO_SCAN_BASE_PACKAGES;
* @author liaozan * @author liaozan
* @since 2023-04-28 * @since 2023-04-28
*/ */
public class DubboPropertiesPreparedEventListener extends PropertiesPreparedEventListenerAdapter<DubboProperties> { public class DubboPropertiesPreparedEventListener extends GenericPropertiesPreparedEventListener<DubboProperties> {
public static final String DUBBO_APPLICATION_NAME = "dubbo.application.name"; public static final String DUBBO_APPLICATION_NAME = "dubbo.application.name";
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
@Override @Override
protected void onPropertiesPrepared(PropertiesPreparedEvent event, DubboProperties properties) { protected void onPropertiesPrepared(PropertiesPreparedEvent event, DubboProperties properties) {
ConfigurableEnvironment environment = event.getEnvironment(); ConfigurableEnvironment environment = event.getEnvironment();
......
...@@ -3,10 +3,8 @@ package com.schbrain.framework.autoconfigure.logger; ...@@ -3,10 +3,8 @@ package com.schbrain.framework.autoconfigure.logger;
import com.schbrain.framework.autoconfigure.logger.apollo.DynamicLoggerConfiguration; import com.schbrain.framework.autoconfigure.logger.apollo.DynamicLoggerConfiguration;
import com.schbrain.framework.autoconfigure.logger.properties.LoggerProperties; import com.schbrain.framework.autoconfigure.logger.properties.LoggerProperties;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered;
/** /**
* @author liaozan * @author liaozan
...@@ -14,7 +12,6 @@ import org.springframework.core.Ordered; ...@@ -14,7 +12,6 @@ import org.springframework.core.Ordered;
*/ */
@AutoConfiguration @AutoConfiguration
@Import(DynamicLoggerConfiguration.class) @Import(DynamicLoggerConfiguration.class)
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
@EnableConfigurationProperties(LoggerProperties.class) @EnableConfigurationProperties(LoggerProperties.class)
public class LoggerAutoConfiguration { public class LoggerAutoConfiguration {
......
...@@ -8,8 +8,8 @@ import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; ...@@ -8,8 +8,8 @@ import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.schbrain.common.util.InetUtils; import com.schbrain.common.util.InetUtils;
import com.schbrain.common.util.InetUtils.HostInfo; import com.schbrain.common.util.InetUtils.HostInfo;
import com.schbrain.framework.autoconfigure.apollo.listener.GenericPropertiesPreparedEventListener;
import com.schbrain.framework.autoconfigure.apollo.listener.PropertiesPreparedEvent; import com.schbrain.framework.autoconfigure.apollo.listener.PropertiesPreparedEvent;
import com.schbrain.framework.autoconfigure.apollo.listener.PropertiesPreparedEventListenerAdapter;
import com.schbrain.framework.autoconfigure.logger.LoggerConfigurationInitializer; import com.schbrain.framework.autoconfigure.logger.LoggerConfigurationInitializer;
import com.schbrain.framework.autoconfigure.logger.properties.LoggerProperties; import com.schbrain.framework.autoconfigure.logger.properties.LoggerProperties;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
...@@ -25,7 +25,7 @@ import static org.springframework.boot.context.logging.LoggingApplicationListene ...@@ -25,7 +25,7 @@ import static org.springframework.boot.context.logging.LoggingApplicationListene
* @author liaozan * @author liaozan
* @since 2023-04-28 * @since 2023-04-28
*/ */
public class LoggerPropertiesPreparedEventListener extends PropertiesPreparedEventListenerAdapter<LoggerProperties> { public class LoggerPropertiesPreparedEventListener extends GenericPropertiesPreparedEventListener<LoggerProperties> {
@Override @Override
protected void onPropertiesPrepared(PropertiesPreparedEvent event, LoggerProperties properties) { protected void onPropertiesPrepared(PropertiesPreparedEvent event, LoggerProperties properties) {
......
...@@ -2,7 +2,7 @@ package com.schbrain.framework.autoconfigure.mybatis.datasource; ...@@ -2,7 +2,7 @@ package com.schbrain.framework.autoconfigure.mybatis.datasource;
import com.schbrain.framework.autoconfigure.mybatis.datasource.customizer.DataSourceCustomizer; import com.schbrain.framework.autoconfigure.mybatis.datasource.customizer.DataSourceCustomizer;
import com.schbrain.framework.autoconfigure.mybatis.properties.DataSourceConnectionProperties; import com.schbrain.framework.autoconfigure.mybatis.properties.DataSourceConnectionProperties;
import com.schbrain.framework.support.spring.BeanPostProcessorAdapter; import com.schbrain.framework.support.spring.GenericBeanPostProcessor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
...@@ -15,7 +15,7 @@ import java.sql.SQLException; ...@@ -15,7 +15,7 @@ import java.sql.SQLException;
* @since 2021/11/23 * @since 2021/11/23
*/ */
@Slf4j @Slf4j
public class DataSourceConnectionPostProcessor extends BeanPostProcessorAdapter<DataSource> { public class DataSourceConnectionPostProcessor extends GenericBeanPostProcessor<DataSource> {
// use ObjectProvider to avoid early initialization beans // use ObjectProvider to avoid early initialization beans
private final ObjectProvider<DataSourceCustomizer> customizers; private final ObjectProvider<DataSourceCustomizer> customizers;
...@@ -29,14 +29,13 @@ public class DataSourceConnectionPostProcessor extends BeanPostProcessorAdapter< ...@@ -29,14 +29,13 @@ public class DataSourceConnectionPostProcessor extends BeanPostProcessorAdapter<
@Override @Override
protected void processBeforeInitialization(DataSource dataSource, String beanName) throws BeansException { protected void processBeforeInitialization(DataSource dataSource, String beanName) throws BeansException {
DataSourceConnectionProperties connectionProperties = this.connectionProperties.getObject(); this.connectionProperties.ifAvailable(properties -> customizers.orderedStream().forEach(customizer -> {
customizers.orderedStream().forEach(customizer -> {
try { try {
customizer.customize(dataSource, connectionProperties); customizer.customize(dataSource, properties);
} catch (SQLException e) { } catch (SQLException e) {
log.warn("failed to customize dataSource connectionProperties", e); log.warn("Failed to customize dataSource connectionProperties", e);
} }
}); }));
} }
} }
\ No newline at end of file
...@@ -4,21 +4,18 @@ import org.springframework.beans.BeansException; ...@@ -4,21 +4,18 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor; import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;
import org.springframework.context.*; import org.springframework.context.*;
import org.springframework.core.ResolvableType;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
/** /**
* @author liaozan * @author liaozan
* @since 2021/11/22 * @since 2021/11/22
*/ */
@SuppressWarnings({"unchecked", "unused"}) @SuppressWarnings({"unchecked", "unused"})
public abstract class BeanPostProcessorAdapter<T> implements SmartInstantiationAwareBeanPostProcessor, ApplicationContextAware { public abstract class GenericBeanPostProcessor<T> implements SmartInstantiationAwareBeanPostProcessor, ApplicationContextAware {
private final Class<T> beanType; private final ResolvableType beanType;
protected ConfigurableApplicationContext applicationContext; protected ConfigurableApplicationContext applicationContext;
...@@ -26,38 +23,37 @@ public abstract class BeanPostProcessorAdapter<T> implements SmartInstantiationA ...@@ -26,38 +23,37 @@ public abstract class BeanPostProcessorAdapter<T> implements SmartInstantiationA
protected ConfigurableEnvironment environment; protected ConfigurableEnvironment environment;
public BeanPostProcessorAdapter() { public GenericBeanPostProcessor() {
ParameterizedType parameterizedType = (ParameterizedType) getClass().getGenericSuperclass(); this.beanType = ResolvableType.forInstance(this).getSuperType().getGeneric(0);
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
this.beanType = (Class<T>) actualTypeArguments[0];
} }
@Override @Override
public final Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException { public final Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
if (ClassUtils.isAssignable(beanType, beanClass)) { if (beanType.isAssignableFrom(beanClass)) {
return doPostProcessBeforeInstantiation((Class<T>) beanClass); return doPostProcessBeforeInstantiation((Class<T>) beanClass);
} }
return null; return null;
} }
@Override @Override
public final Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (ClassUtils.isAssignableValue(beanType, bean)) {
return doPostProcessBeforeInitialization((T) bean, beanName);
}
return bean;
}
public final boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException { public final boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
if (ClassUtils.isAssignableValue(beanType, bean)) { if (beanType.isInstance(bean)) {
return doPostProcessAfterInstantiation((T) bean); return doPostProcessAfterInstantiation((T) bean);
} }
return true; return true;
} }
@Override
public final Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (beanType.isInstance(bean)) {
return doPostProcessBeforeInitialization((T) bean, beanName);
}
return bean;
}
@Override @Override
public final Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { public final Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (ClassUtils.isAssignableValue(beanType, bean)) { if (beanType.isInstance(bean)) {
return doPostProcessAfterInitialization((T) bean, beanName); return doPostProcessAfterInitialization((T) bean, beanName);
} }
return bean; return bean;
...@@ -65,16 +61,12 @@ public abstract class BeanPostProcessorAdapter<T> implements SmartInstantiationA ...@@ -65,16 +61,12 @@ public abstract class BeanPostProcessorAdapter<T> implements SmartInstantiationA
@Override @Override
public void setApplicationContext(ApplicationContext context) throws BeansException { public void setApplicationContext(ApplicationContext context) throws BeansException {
Assert.isInstanceOf(ConfigurableApplicationContext.class, context, "require ConfigurableApplicationContext"); Assert.isInstanceOf(ConfigurableApplicationContext.class, context, "Require ConfigurableApplicationContext");
this.applicationContext = (ConfigurableApplicationContext) context; this.applicationContext = (ConfigurableApplicationContext) context;
this.beanFactory = this.applicationContext.getBeanFactory(); this.beanFactory = this.applicationContext.getBeanFactory();
this.environment = this.applicationContext.getEnvironment(); this.environment = this.applicationContext.getEnvironment();
} }
public final Class<T> getBeanType() {
return beanType;
}
// region Instantiation // region Instantiation
protected T doPostProcessBeforeInstantiation(Class<T> beanClass) { protected T doPostProcessBeforeInstantiation(Class<T> beanClass) {
return null; return null;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment