Commit 5c3e0dd9 authored by liaozan's avatar liaozan 🏀

Reorder dependencies

parent 37664e38
......@@ -19,6 +19,10 @@
<groupId>com.schbrain.common</groupId>
<artifactId>common</artifactId>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
......
This diff is collapsed.
......@@ -2,37 +2,31 @@ package com.schbrain.framework.autoconfigure.apollo.listener;
import com.schbrain.common.util.support.ConfigurableProperties;
import org.apache.commons.logging.Log;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import org.springframework.core.ResolvableType;
/**
* @author liaozan
* @since 2023-04-28
*/
@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;
public PropertiesPreparedEventListenerAdapter() {
ParameterizedType parameterizedType = (ParameterizedType) getClass().getGenericSuperclass();
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
this.propertyType = (Class<T>) actualTypeArguments[0];
public GenericPropertiesPreparedEventListener() {
this.propertiesType = ResolvableType.forInstance(this).getSuperType().getGeneric(0);
}
@Override
public void onApplicationEvent(PropertiesPreparedEvent event) {
if (event.getConfigurableProperties().getClass() == propertyType) {
this.log = event.getDeferredLogFactory().getLog(this.getClass());
if (propertiesType.isInstance(event.getConfigurableProperties())) {
this.log = event.getDeferredLogFactory().getLog(getClass());
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;
import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;
/**
* @author liaozan
* @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;
import com.alibaba.fastjson2.JSONFactory;
import com.google.common.collect.Maps;
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.PropertiesPreparedEventListenerAdapter;
import com.schbrain.framework.autoconfigure.dubbo.properties.DubboProperties;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.spring.ConfigCenterBean;
import org.apache.dubbo.config.spring.util.EnvironmentUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import java.util.Map;
......@@ -21,10 +22,15 @@ import static org.apache.dubbo.config.ConfigKeys.DUBBO_SCAN_BASE_PACKAGES;
* @author liaozan
* @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";
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
@Override
protected void onPropertiesPrepared(PropertiesPreparedEvent event, DubboProperties properties) {
ConfigurableEnvironment environment = event.getEnvironment();
......
......@@ -3,10 +3,8 @@ package com.schbrain.framework.autoconfigure.logger;
import com.schbrain.framework.autoconfigure.logger.apollo.DynamicLoggerConfiguration;
import com.schbrain.framework.autoconfigure.logger.properties.LoggerProperties;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered;
/**
* @author liaozan
......@@ -14,7 +12,6 @@ import org.springframework.core.Ordered;
*/
@AutoConfiguration
@Import(DynamicLoggerConfiguration.class)
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
@EnableConfigurationProperties(LoggerProperties.class)
public class LoggerAutoConfiguration {
......
......@@ -8,8 +8,8 @@ import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.google.common.collect.Maps;
import com.schbrain.common.util.InetUtils;
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.PropertiesPreparedEventListenerAdapter;
import com.schbrain.framework.autoconfigure.logger.LoggerConfigurationInitializer;
import com.schbrain.framework.autoconfigure.logger.properties.LoggerProperties;
import org.springframework.core.env.ConfigurableEnvironment;
......@@ -25,7 +25,7 @@ import static org.springframework.boot.context.logging.LoggingApplicationListene
* @author liaozan
* @since 2023-04-28
*/
public class LoggerPropertiesPreparedEventListener extends PropertiesPreparedEventListenerAdapter<LoggerProperties> {
public class LoggerPropertiesPreparedEventListener extends GenericPropertiesPreparedEventListener<LoggerProperties> {
@Override
protected void onPropertiesPrepared(PropertiesPreparedEvent event, LoggerProperties properties) {
......
......@@ -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.properties.DataSourceConnectionProperties;
import com.schbrain.framework.support.spring.BeanPostProcessorAdapter;
import com.schbrain.framework.support.spring.GenericBeanPostProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectProvider;
......@@ -15,7 +15,7 @@ import java.sql.SQLException;
* @since 2021/11/23
*/
@Slf4j
public class DataSourceConnectionPostProcessor extends BeanPostProcessorAdapter<DataSource> {
public class DataSourceConnectionPostProcessor extends GenericBeanPostProcessor<DataSource> {
// use ObjectProvider to avoid early initialization beans
private final ObjectProvider<DataSourceCustomizer> customizers;
......@@ -29,14 +29,13 @@ public class DataSourceConnectionPostProcessor extends BeanPostProcessorAdapter<
@Override
protected void processBeforeInitialization(DataSource dataSource, String beanName) throws BeansException {
DataSourceConnectionProperties connectionProperties = this.connectionProperties.getObject();
customizers.orderedStream().forEach(customizer -> {
this.connectionProperties.ifAvailable(properties -> customizers.orderedStream().forEach(customizer -> {
try {
customizer.customize(dataSource, connectionProperties);
customizer.customize(dataSource, properties);
} 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;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;
import org.springframework.context.*;
import org.springframework.core.ResolvableType;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
/**
* @author liaozan
* @since 2021/11/22
*/
@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;
......@@ -26,38 +23,37 @@ public abstract class BeanPostProcessorAdapter<T> implements SmartInstantiationA
protected ConfigurableEnvironment environment;
public BeanPostProcessorAdapter() {
ParameterizedType parameterizedType = (ParameterizedType) getClass().getGenericSuperclass();
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
this.beanType = (Class<T>) actualTypeArguments[0];
public GenericBeanPostProcessor() {
this.beanType = ResolvableType.forInstance(this).getSuperType().getGeneric(0);
}
@Override
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 null;
}
@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 {
if (ClassUtils.isAssignableValue(beanType, bean)) {
if (beanType.isInstance(bean)) {
return doPostProcessAfterInstantiation((T) bean);
}
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
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 bean;
......@@ -65,16 +61,12 @@ public abstract class BeanPostProcessorAdapter<T> implements SmartInstantiationA
@Override
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.beanFactory = this.applicationContext.getBeanFactory();
this.environment = this.applicationContext.getEnvironment();
}
public final Class<T> getBeanType() {
return beanType;
}
// region Instantiation
protected T doPostProcessBeforeInstantiation(Class<T> beanClass) {
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