mirror of
https://github.moeyy.xyz/https://github.com/GeWuYou/forgeboot
synced 2025-10-27 23:22:09 +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
|
||||
* @since 2025-05-02 11:52:24
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "version")
|
||||
@ConfigurationProperties(prefix = "forgeboot.version")
|
||||
public class VersionProperties {
|
||||
/**
|
||||
* API前缀
|
||||
|
||||
@ -7,6 +7,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
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
|
||||
@EnableConfigurationProperties(VersionProperties::class)
|
||||
open class VersionAutoConfiguration(
|
||||
private val versionProperties: VersionProperties,
|
||||
private val corsConfigurationSource: CorsConfigurationSource,
|
||||
) {
|
||||
open class VersionAutoConfiguration {
|
||||
/**
|
||||
* 创建并配置一个 ApiVersionRequestMappingHandlerMapping 实例
|
||||
*
|
||||
@ -30,9 +28,13 @@ open class VersionAutoConfiguration(
|
||||
* @return ApiVersionRequestMappingHandlerMapping 实例,用于处理基于 API 版本的请求映射
|
||||
*/
|
||||
@Bean
|
||||
open fun apiVersionRequestMappingHandlerMapping(): ApiVersionRequestMappingHandlerMapping {
|
||||
open fun apiVersionRequestMappingHandlerMapping(
|
||||
versionProperties: VersionProperties,
|
||||
corsConfigurationSource: CorsConfigurationSource,
|
||||
): RequestMappingHandlerMapping {
|
||||
log.info("创建 API 版本请求映射处理程序映射")
|
||||
return ApiVersionRequestMappingHandlerMapping(versionProperties).also {
|
||||
it.order = Int.MIN_VALUE
|
||||
it.corsConfigurationSource = corsConfigurationSource
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user