mirror of
https://github.moeyy.xyz/https://github.com/GeWuYou/forgeboot
synced 2025-10-28 02:36:39 +08:00
feat(version): The API version management feature is optimized
- Adjust the VersionAutoConfiguration class to move dependency injection into the method parameters - Add Int.MIN_VALUE as the priority of the API version request mapping, ensuring that it is higher than the default mapping - Change the configuration prefix of VersionProperties to "forgeboot.version"
This commit is contained in:
parent
b1811f5941
commit
0ca32efc02
@ -11,7 +11,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||||||
* @author gewuyou
|
* @author gewuyou
|
||||||
* @since 2025-05-02 11:52:24
|
* @since 2025-05-02 11:52:24
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "version")
|
@ConfigurationProperties(prefix = "forgeboot.version")
|
||||||
public class VersionProperties {
|
public class VersionProperties {
|
||||||
/**
|
/**
|
||||||
* API前缀
|
* API前缀
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
|||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
import org.springframework.web.cors.CorsConfigurationSource
|
import org.springframework.web.cors.CorsConfigurationSource
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*版本自动配置
|
*版本自动配置
|
||||||
@ -16,10 +17,7 @@ import org.springframework.web.cors.CorsConfigurationSource
|
|||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties(VersionProperties::class)
|
@EnableConfigurationProperties(VersionProperties::class)
|
||||||
open class VersionAutoConfiguration(
|
open class VersionAutoConfiguration {
|
||||||
private val versionProperties: VersionProperties,
|
|
||||||
private val corsConfigurationSource: CorsConfigurationSource,
|
|
||||||
) {
|
|
||||||
/**
|
/**
|
||||||
* 创建并配置一个 ApiVersionRequestMappingHandlerMapping 实例
|
* 创建并配置一个 ApiVersionRequestMappingHandlerMapping 实例
|
||||||
*
|
*
|
||||||
@ -30,9 +28,13 @@ open class VersionAutoConfiguration(
|
|||||||
* @return ApiVersionRequestMappingHandlerMapping 实例,用于处理基于 API 版本的请求映射
|
* @return ApiVersionRequestMappingHandlerMapping 实例,用于处理基于 API 版本的请求映射
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
open fun apiVersionRequestMappingHandlerMapping(): ApiVersionRequestMappingHandlerMapping {
|
open fun apiVersionRequestMappingHandlerMapping(
|
||||||
|
versionProperties: VersionProperties,
|
||||||
|
corsConfigurationSource: CorsConfigurationSource,
|
||||||
|
): RequestMappingHandlerMapping {
|
||||||
log.info("创建 API 版本请求映射处理程序映射")
|
log.info("创建 API 版本请求映射处理程序映射")
|
||||||
return ApiVersionRequestMappingHandlerMapping(versionProperties).also {
|
return ApiVersionRequestMappingHandlerMapping(versionProperties).also {
|
||||||
|
it.order = Int.MIN_VALUE
|
||||||
it.corsConfigurationSource = corsConfigurationSource
|
it.corsConfigurationSource = corsConfigurationSource
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user