添加自动装配排序.

This commit is contained in:
lijiahang
2023-07-12 10:09:11 +08:00
parent ab25570a86
commit 5c8681599b
15 changed files with 85 additions and 6 deletions

View File

@@ -1,8 +1,10 @@
package com.orion.ops.framework.common.config;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import com.orion.ops.framework.common.thread.ThreadPoolMdcTaskExecutor;
import com.orion.spring.SpringHolder;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
@@ -20,6 +22,7 @@ import java.util.concurrent.ThreadPoolExecutor;
*/
@EnableAsync
@AutoConfiguration
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_COMMON)
@EnableConfigurationProperties(ThreadPoolConfig.class)
public class OrionCommonAutoConfiguration {

View File

@@ -0,0 +1,42 @@
package com.orion.ops.framework.common.constant;
/**
* 自动装配排序常量
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/7/11 17:55
*/
public interface AutoConfigureOrderConst {
int FRAMEWORK_COMMON = Integer.MIN_VALUE + 1000;
int FRAMEWORK_WEB = Integer.MIN_VALUE + 1100;
int FRAMEWORK_SECURITY = Integer.MIN_VALUE + 1200;
int FRAMEWORK_SECURITY_CRYPTO = Integer.MIN_VALUE + 1250;
int FRAMEWORK_WEBSOCKET = Integer.MIN_VALUE + 1300;
int FRAMEWORK_DESENSITIZE = Integer.MIN_VALUE + 1400;
int FRAMEWORK_LOG = Integer.MIN_VALUE + 1500;
int FRAMEWORK_JOB = Integer.MIN_VALUE + 1600;
int FRAMEWORK_SWAGGER = Integer.MIN_VALUE + 1700;
int FRAMEWORK_DATASOURCE = Integer.MIN_VALUE + 1800;
int FRAMEWORK_MYBATIS = Integer.MIN_VALUE + 1900;
int FRAMEWORK_REDIS = Integer.MIN_VALUE + 2000;
int FRAMEWORK_STORAGE = Integer.MIN_VALUE + 2100;
int FRAMEWORK_MONITOR = Integer.MIN_VALUE + 2200;
int FRAMEWORK_BANNER = Integer.MIN_VALUE + 2300;
}

View File

@@ -1,7 +1,9 @@
package com.orion.ops.framework.banner.config;
import com.orion.ops.framework.banner.core.BannerApplicationRunner;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.context.annotation.Bean;
/**
@@ -12,6 +14,7 @@ import org.springframework.context.annotation.Bean;
* @since 2023/6/15 16:16
*/
@AutoConfiguration
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_BANNER)
public class OrionBannerAutoConfiguration {
/**

View File

@@ -1,8 +1,10 @@
package com.orion.ops.framework.datasource.config;
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import com.orion.ops.framework.datasource.core.filter.DruidAdRemoveFilter;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
@@ -17,6 +19,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
* @since 2023/6/23 17:22
*/
@AutoConfiguration
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_DATASOURCE)
@EnableTransactionManagement(proxyTargetClass = true)
@EnableConfigurationProperties(DruidStatProperties.class)
public class OrionDatasourceAutoConfiguration {

View File

@@ -1,6 +1,8 @@
package com.orion.ops.framework.job.config;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
@@ -17,6 +19,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
*/
@EnableScheduling
@AutoConfiguration
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_JOB)
public class OrionSchedulerAutoConfiguration {
/**

View File

@@ -1,5 +1,6 @@
package com.orion.ops.framework.log.config;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import com.orion.ops.framework.common.constant.InterceptorOrderConst;
import com.orion.ops.framework.log.core.config.LogPrinterConfig;
import com.orion.ops.framework.log.core.interceptor.LogPrinterInterceptor;
@@ -7,6 +8,7 @@ import com.orion.ops.framework.log.core.interceptor.PrettyLogPrinterInterceptor;
import com.orion.ops.framework.log.core.interceptor.RowLogPrinterInterceptor;
import org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -22,6 +24,7 @@ import javax.annotation.Resource;
* @since 2023/6/16 18:18
*/
@AutoConfiguration
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_LOG)
@EnableConfigurationProperties(LogPrinterConfig.class)
public class OrionLogPrinterConfiguration {

View File

@@ -2,10 +2,11 @@ package com.orion.ops.framework.monitor.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import de.codecentric.boot.admin.server.utils.jackson.AdminServerModule;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
@@ -19,7 +20,7 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
*/
@EnableAdminServer
@AutoConfiguration
@AutoConfigureAfter(name = "com.orion.ops.framework.web.config.OrionWebAutoConfiguration")
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_MONITOR)
public class OrionAdminAutoConfiguration {
/**

View File

@@ -1,6 +1,7 @@
package com.orion.ops.framework.mybatis.config;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import com.orion.ops.framework.common.constant.FilterOrderConst;
import com.orion.ops.framework.common.filter.FilterCreator;
import com.orion.ops.framework.mybatis.core.cache.CacheClearFilter;
@@ -8,6 +9,7 @@ import com.orion.ops.framework.mybatis.core.handler.FieldFillHandler;
import org.apache.ibatis.annotations.Mapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
@@ -20,6 +22,7 @@ import org.springframework.context.annotation.Bean;
* @since 2023/6/23 18:35
*/
@AutoConfiguration
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_MYBATIS)
@MapperScan(value = "com.orion.ops.module.*.dao", annotationClass = Mapper.class, lazyInitialization = "true")
public class OrionMybatisAutoConfiguration {

View File

@@ -1,6 +1,8 @@
package com.orion.ops.framework.redis.config;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
@@ -20,6 +22,7 @@ import org.springframework.data.redis.serializer.RedisSerializer;
* @since 2023/6/28 14:44
*/
@AutoConfiguration
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_REDIS)
@EnableCaching
@EnableConfigurationProperties({CacheProperties.class})
public class OrionRedisAutoConfiguration {

View File

@@ -1,9 +1,11 @@
package com.orion.ops.framework.security.config;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import com.orion.ops.framework.common.crypto.ValueCrypto;
import com.orion.ops.framework.common.utils.CryptoUtils;
import com.orion.ops.framework.security.core.crypto.aes.AesCryptoProcessor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@@ -20,6 +22,7 @@ import javax.annotation.Resource;
*/
@AutoConfiguration
@EnableConfigurationProperties(CryptoConfig.class)
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_SECURITY_CRYPTO)
public class OrionCryptoAutoConfiguration {
@Resource

View File

@@ -1,5 +1,6 @@
package com.orion.ops.framework.security.config;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import com.orion.ops.framework.security.core.context.TransmittableThreadLocalSecurityContextHolderStrategy;
import com.orion.ops.framework.security.core.filter.TokenAuthenticationFilter;
import com.orion.ops.framework.security.core.handler.AuthenticationEntryPointHandler;
@@ -11,6 +12,7 @@ import com.orion.ops.framework.security.core.strategy.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
@@ -40,6 +42,7 @@ import java.util.List;
* @since 2023/7/6 15:05
*/
@AutoConfiguration
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_SECURITY)
@EnableConfigurationProperties(SecurityConfig.class)
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class OrionSecurityAutoConfiguration {
@@ -115,8 +118,8 @@ public class OrionSecurityAutoConfiguration {
* @return token 认证过滤器
*/
@Bean
@ConditionalOnBean(SecurityFrameworkService.class)
public TokenAuthenticationFilter authenticationTokenFilter(SecurityFrameworkService delegate) {
@ConditionalOnBean(SecurityFrameworkServiceDelegate.class)
public TokenAuthenticationFilter authenticationTokenFilter(SecurityFrameworkServiceDelegate delegate) {
return new TokenAuthenticationFilter(delegate);
}

View File

@@ -29,9 +29,9 @@ public class ConsoleAuthorizeRequestsCustomizer extends AuthorizeRequestsCustomi
.antMatchers("/swagger-resources/**", "/webjars/**", "/*/api-docs").anonymous()
// druid 监控
.antMatchers("/druid/**").anonymous()
// actuator 安全配置 TODO TEST
// actuator 安全配置
.antMatchers(managementEndpoints, managementEndpoints + "/**").anonymous()
// admin 安全配置 TODO TEST
// admin
.antMatchers(adminSeverContextPath, adminSeverContextPath + "/**").anonymous();
}

View File

@@ -1,8 +1,10 @@
package com.orion.ops.framework.storage.config;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import com.orion.ops.framework.storage.core.client.FileClient;
import com.orion.ops.framework.storage.core.client.local.LocalFileClient;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@@ -20,6 +22,7 @@ import javax.annotation.Resource;
* TODO 后续添加 FAST MINIO OSS 等
*/
@AutoConfiguration
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_STORAGE)
@EnableConfigurationProperties(StorageConfig.class)
public class OrionStorageAutoConfiguration {

View File

@@ -1,5 +1,6 @@
package com.orion.ops.framework.swagger.config;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
@@ -15,6 +16,7 @@ import org.springdoc.core.customizers.ServerBaseUrlCustomizer;
import org.springdoc.core.providers.JavadocProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -39,6 +41,7 @@ import java.util.Optional;
@EnableConfigurationProperties(SwaggerProperties.class)
@ConditionalOnProperty(prefix = "springdoc.api-docs", name = "enabled", havingValue = "true", matchIfMissing = true)
@AutoConfiguration
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_SWAGGER)
public class OrionSwaggerAutoConfiguration {
private static String orionApiPrefix;

View File

@@ -1,8 +1,10 @@
package com.orion.ops.framework.websocket.config;
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
import com.orion.ops.framework.websocket.core.WebsocketContainerConfig;
import com.orion.ops.framework.websocket.interceptor.UserHandshakeInterceptor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
@@ -18,6 +20,7 @@ import org.springframework.web.socket.server.standard.ServletServerContainerFact
*/
@EnableWebSocket
@AutoConfiguration
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_WEBSOCKET)
@EnableConfigurationProperties(WebsocketContainerConfig.class)
public class OrionWebsocketAutoConfiguration {