Commit cd5e6319d90454c5b0d9f7da020de7d19a9812c8
1 parent
c1df35d3
【增强】一键改包:支持 site、org 等包
Showing
7 changed files
with
18 additions
and
9 deletions
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.mybatis.config; |
| 3 | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.handler.DefaultDBFieldHandler; |
| 5 | 5 | import com.baomidou.mybatisplus.annotation.DbType; |
| 6 | +import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; | |
| 6 | 7 | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
| 7 | 8 | import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator; |
| 8 | 9 | import com.baomidou.mybatisplus.extension.incrementer.*; |
| ... | ... | @@ -20,7 +21,7 @@ import org.springframework.core.env.ConfigurableEnvironment; |
| 20 | 21 | * |
| 21 | 22 | * @author 芋道源码 |
| 22 | 23 | */ |
| 23 | -@AutoConfiguration | |
| 24 | +@AutoConfiguration(before = MybatisPlusAutoConfiguration.class) // 目的:先于 MyBatis Plus 自动配置,避免 @MapperScan 可能扫描不到 Mapper 打印 warn 日志 | |
| 24 | 25 | @MapperScan(value = "${yudao.info.base-package}", annotationClass = Mapper.class, |
| 25 | 26 | lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试 |
| 26 | 27 | public class YudaoMybatisAutoConfiguration { | ... | ... |
yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoRedisAutoConfiguration.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.redis.config; |
| 3 | 3 | import cn.hutool.core.util.ReflectUtil; |
| 4 | 4 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 5 | 5 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; |
| 6 | +import org.redisson.spring.starter.RedissonAutoConfigurationV2; | |
| 6 | 7 | import org.springframework.boot.autoconfigure.AutoConfiguration; |
| 7 | 8 | import org.springframework.context.annotation.Bean; |
| 8 | 9 | import org.springframework.data.redis.connection.RedisConnectionFactory; |
| ... | ... | @@ -12,7 +13,7 @@ import org.springframework.data.redis.serializer.RedisSerializer; |
| 12 | 13 | /** |
| 13 | 14 | * Redis 配置类 |
| 14 | 15 | */ |
| 15 | -@AutoConfiguration | |
| 16 | +@AutoConfiguration(before = RedissonAutoConfigurationV2.class) // 目的:使用自己定义的 RedisTemplate Bean | |
| 16 | 17 | public class YudaoRedisAutoConfiguration { |
| 17 | 18 | |
| 18 | 19 | /** | ... | ... |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoSecurityAutoConfiguration.java
| ... | ... | @@ -10,8 +10,10 @@ import cn.iocoder.yudao.framework.security.core.service.SecurityFrameworkService |
| 10 | 10 | import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler; |
| 11 | 11 | import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi; |
| 12 | 12 | import cn.iocoder.yudao.module.system.api.permission.PermissionApi; |
| 13 | +import jakarta.annotation.Resource; | |
| 13 | 14 | import org.springframework.beans.factory.config.MethodInvokingFactoryBean; |
| 14 | 15 | import org.springframework.boot.autoconfigure.AutoConfiguration; |
| 16 | +import org.springframework.boot.autoconfigure.AutoConfigureOrder; | |
| 15 | 17 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 16 | 18 | import org.springframework.context.annotation.Bean; |
| 17 | 19 | import org.springframework.security.core.context.SecurityContextHolder; |
| ... | ... | @@ -20,8 +22,6 @@ import org.springframework.security.crypto.password.PasswordEncoder; |
| 20 | 22 | import org.springframework.security.web.AuthenticationEntryPoint; |
| 21 | 23 | import org.springframework.security.web.access.AccessDeniedHandler; |
| 22 | 24 | |
| 23 | -import jakarta.annotation.Resource; | |
| 24 | - | |
| 25 | 25 | /** |
| 26 | 26 | * Spring Security 自动配置类,主要用于相关组件的配置 |
| 27 | 27 | * |
| ... | ... | @@ -31,6 +31,7 @@ import jakarta.annotation.Resource; |
| 31 | 31 | * @author 芋道源码 |
| 32 | 32 | */ |
| 33 | 33 | @AutoConfiguration |
| 34 | +@AutoConfigureOrder(-1) // 目的:先于 Spring Security 自动配置,避免一键改包后,org.* 基础包无法生效 | |
| 34 | 35 | @EnableConfigurationProperties(SecurityProperties.class) |
| 35 | 36 | public class YudaoSecurityAutoConfiguration { |
| 36 | 37 | ... | ... |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoWebSecurityConfigurerAdapter.java
| ... | ... | @@ -5,14 +5,16 @@ import cn.iocoder.yudao.framework.security.core.filter.TokenAuthenticationFilter |
| 5 | 5 | import cn.iocoder.yudao.framework.web.config.WebProperties; |
| 6 | 6 | import com.google.common.collect.HashMultimap; |
| 7 | 7 | import com.google.common.collect.Multimap; |
| 8 | +import jakarta.annotation.Resource; | |
| 9 | +import jakarta.annotation.security.PermitAll; | |
| 8 | 10 | import org.springframework.boot.autoconfigure.AutoConfiguration; |
| 11 | +import org.springframework.boot.autoconfigure.AutoConfigureOrder; | |
| 9 | 12 | import org.springframework.context.ApplicationContext; |
| 10 | 13 | import org.springframework.context.annotation.Bean; |
| 11 | 14 | import org.springframework.http.HttpMethod; |
| 12 | 15 | import org.springframework.security.authentication.AuthenticationManager; |
| 13 | 16 | import org.springframework.security.config.Customizer; |
| 14 | 17 | import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; |
| 15 | -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | |
| 16 | 18 | import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; |
| 17 | 19 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| 18 | 20 | import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; |
| ... | ... | @@ -27,8 +29,6 @@ import org.springframework.web.method.HandlerMethod; |
| 27 | 29 | import org.springframework.web.servlet.mvc.method.RequestMappingInfo; |
| 28 | 30 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; |
| 29 | 31 | |
| 30 | -import jakarta.annotation.Resource; | |
| 31 | -import jakarta.annotation.security.PermitAll; | |
| 32 | 32 | import java.util.List; |
| 33 | 33 | import java.util.Map; |
| 34 | 34 | import java.util.Set; |
| ... | ... | @@ -39,6 +39,7 @@ import java.util.Set; |
| 39 | 39 | * @author 芋道源码 |
| 40 | 40 | */ |
| 41 | 41 | @AutoConfiguration |
| 42 | +@AutoConfigureOrder(-1) // 目的:先于 Spring Security 自动配置,避免一键改包后,org.* 基础包无法生效 | |
| 42 | 43 | @EnableMethodSecurity(securedEnabled = true) |
| 43 | 44 | public class YudaoWebSecurityConfigurerAdapter { |
| 44 | 45 | ... | ... |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/config/YudaoSwaggerAutoConfiguration.java
| ... | ... | @@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
| 23 | 23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| 24 | 24 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 25 | 25 | import org.springframework.context.annotation.Bean; |
| 26 | +import org.springframework.context.annotation.Primary; | |
| 26 | 27 | import org.springframework.http.HttpHeaders; |
| 27 | 28 | |
| 28 | 29 | import java.util.HashMap; |
| ... | ... | @@ -91,6 +92,7 @@ public class YudaoSwaggerAutoConfiguration { |
| 91 | 92 | * 自定义 OpenAPI 处理器 |
| 92 | 93 | */ |
| 93 | 94 | @Bean |
| 95 | + @Primary // 目的:以我们创建的 OpenAPIService Bean 为主,避免一键改包后,启动报错! | |
| 94 | 96 | public OpenAPIService openApiBuilder(Optional<OpenAPI> openAPI, |
| 95 | 97 | SecurityService securityParser, |
| 96 | 98 | SpringDocConfigProperties springDocConfigProperties, |
| ... | ... | @@ -98,7 +100,6 @@ public class YudaoSwaggerAutoConfiguration { |
| 98 | 100 | Optional<List<OpenApiBuilderCustomizer>> openApiBuilderCustomizers, |
| 99 | 101 | Optional<List<ServerBaseUrlCustomizer>> serverBaseUrlCustomizers, |
| 100 | 102 | Optional<JavadocProvider> javadocProvider) { |
| 101 | - | |
| 102 | 103 | return new OpenAPIService(openAPI, securityParser, springDocConfigProperties, |
| 103 | 104 | propertyResolverUtils, openApiBuilderCustomizers, serverBaseUrlCustomizers, javadocProvider); |
| 104 | 105 | } | ... | ... |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java
| ... | ... | @@ -9,6 +9,7 @@ import cn.iocoder.yudao.framework.web.core.handler.GlobalResponseBodyHandler; |
| 9 | 9 | import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; |
| 10 | 10 | import org.springframework.beans.factory.annotation.Value; |
| 11 | 11 | import org.springframework.boot.autoconfigure.AutoConfiguration; |
| 12 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | |
| 12 | 13 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| 13 | 14 | import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration; |
| 14 | 15 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| ... | ... | @@ -122,7 +123,9 @@ public class YudaoWebAutoConfiguration implements WebMvcConfigurer { |
| 122 | 123 | * @param restTemplateBuilder {@link RestTemplateAutoConfiguration#restTemplateBuilder} |
| 123 | 124 | */ |
| 124 | 125 | @Bean |
| 126 | + @ConditionalOnMissingBean | |
| 125 | 127 | public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) { |
| 126 | 128 | return restTemplateBuilder.build(); |
| 127 | 129 | } |
| 130 | + | |
| 128 | 131 | } | ... | ... |
yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java
| ... | ... | @@ -34,7 +34,8 @@ public class ProjectReactor { |
| 34 | 34 | * 白名单文件,不进行重写,避免出问题 |
| 35 | 35 | */ |
| 36 | 36 | private static final Set<String> WHITE_FILE_TYPES = SetUtils.asSet("gif", "jpg", "svg", "png", // 图片 |
| 37 | - "eot", "woff2", "ttf", "woff"); // 字体 | |
| 37 | + "eot", "woff2", "ttf", "woff", // 字体 | |
| 38 | + "xdb"); // IP 库 | |
| 38 | 39 | |
| 39 | 40 | public static void main(String[] args) { |
| 40 | 41 | long start = System.currentTimeMillis(); | ... | ... |