Compare commits

...

8 Commits

Author SHA1 Message Date
0ca32efc02 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"
2025-05-09 21:35:16 +08:00
b1811f5941 refactor(webmvc): Refactoring the cross-domain configuration of version request mappings - Removed the injectCors method in the VersionAutoConfiguration class
- Set corsConfigurationSource directly in the apiVersionRequestMappingHandlerMapping method
- Removed unnecessary mapping attributes
2025-05-09 20:30:17 +08:00
ae09ddbd8a refactor(webmvc): Optimized the creation logic of API version request mapping handler mappings
- After you create an ApiVersionRequestMappingHandlerMapping instance, assign it to the mapping variable
- This change may help to better manage request mapping, handler mapping, and improve maintainability of your code
2025-05-09 20:17:29 +08:00
f13b21e640 feat(version): Add log output to track cross-domain configuration injections
- Added log output to the injectCors function to log when the cross-domain configuration is injected
2025-05-09 19:53:51 +08:00
da3bd2f714 refactor(forgeboot-webmvc): Removing the unused WebMvcConfigurer import in VersionAutoConfiguration removes the unused WebMvcConfigurer import statement from the VersionAutoConfiguration.kt file, simplifying the structure of the code and improving the readability of the code. 2025-05-09 19:51:41 +08:00
051c0e44da refactor(forgeboot-webmvc): 移除 VersionAutoConfiguration 中未使用的 WebMvcConfigurer 导入移除了 VersionAutoConfiguration.kt 文件中未使用的 WebMvcConfigurer 导入语句,简化了代码结构并提高了代码的可读性。 2025-05-09 18:07:41 +08:00
b2ce2c46dd build(env): Updated the Gitea repository environment variable reference
- Change the "GEWUYOU_GITEA_HOST" environment variable to "GITEA_HOST"
- change "GEWUYOU_GITEA_TOKEN" environment variable to "GITEA_TOKEN"
2025-05-09 18:00:34 +08:00
0920a83e1c feat(version): Cross-domain configuration is supported for API version request mappings
- Inject VersionProperties and CorsConfigurationSource in VersionAutoConfiguration
- Updated the apiVersionRequestMappingHandlerMapping method to add support for cross-origin configuration
- Remove unnecessary comments from R classes
2025-05-09 17:40:47 +08:00
5 changed files with 16 additions and 8 deletions

View File

@ -105,7 +105,7 @@ subprojects {
} }
} }
// Gitea 仓库 // Gitea 仓库
val host = System.getenv("GEWUYOU_GITEA_HOST") val host = System.getenv("GITEA_HOST")
host?.let { host?.let {
maven { maven {
isAllowInsecureProtocol = true isAllowInsecureProtocol = true
@ -113,7 +113,7 @@ subprojects {
url = uri("http://${it}/api/packages/gewuyou/maven") url = uri("http://${it}/api/packages/gewuyou/maven")
credentials(HttpHeaderCredentials::class.java) { credentials(HttpHeaderCredentials::class.java) {
name = "Authorization" name = "Authorization"
value = "token ${System.getenv("GEWUYOU_GITEA_TOKEN")}" value = "token ${System.getenv("GITEA_TOKEN")}"
} }
authentication { authentication {
create("header", HttpHeaderAuthentication::class.java) create("header", HttpHeaderAuthentication::class.java)

View File

@ -1,7 +1,7 @@
// This file is used to define the repositories used by the project. // This file is used to define the repositories used by the project.
repositories { repositories {
mavenLocal() mavenLocal()
val host = System.getenv("GEWUYOU_GITEA_HOST") val host = System.getenv("GITEA_HOST")
host?.let { host?.let {
maven{ maven{
url = uri("http://${host}/api/packages/gewuyou/maven") url = uri("http://${host}/api/packages/gewuyou/maven")

View File

@ -18,7 +18,7 @@ data class R<T>(
val message: String, val message: String,
val data: T? = null, val data: T? = null,
val requestId: String? = null, val requestId: String? = null,
val extra: Map<String, Any?> = emptyMap() // ✅ 扩展字段保存位置 val extra: Map<String, Any?> = emptyMap()
) { ) {
/** /**
* 转换为可变 Map包含 extra 中的字段 * 转换为可变 Map包含 extra 中的字段
@ -33,7 +33,7 @@ data class R<T>(
if (!requestId.isNullOrBlank()) { if (!requestId.isNullOrBlank()) {
map["requestId"] = requestId map["requestId"] = requestId
} }
map.putAll(extra) // ✅ 扁平化合并 map.putAll(extra)
return map return map
} }

View File

@ -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前缀

View File

@ -6,6 +6,8 @@ import com.gewuyou.forgeboot.webmvc.version.mapping.ApiVersionRequestMappingHand
import org.springframework.boot.context.properties.EnableConfigurationProperties 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.servlet.mvc.method.annotation.RequestMappingHandlerMapping
/** /**
*版本自动配置 *版本自动配置
@ -26,8 +28,14 @@ open class VersionAutoConfiguration {
* @return ApiVersionRequestMappingHandlerMapping 实例用于处理基于 API 版本的请求映射 * @return ApiVersionRequestMappingHandlerMapping 实例用于处理基于 API 版本的请求映射
*/ */
@Bean @Bean
open fun apiVersionRequestMappingHandlerMapping(versionProperties: VersionProperties): ApiVersionRequestMappingHandlerMapping { open fun apiVersionRequestMappingHandlerMapping(
versionProperties: VersionProperties,
corsConfigurationSource: CorsConfigurationSource,
): RequestMappingHandlerMapping {
log.info("创建 API 版本请求映射处理程序映射") log.info("创建 API 版本请求映射处理程序映射")
return ApiVersionRequestMappingHandlerMapping(versionProperties).also { it.order = Int.MIN_VALUE } return ApiVersionRequestMappingHandlerMapping(versionProperties).also {
it.order = Int.MIN_VALUE
it.corsConfigurationSource = corsConfigurationSource
}
} }
} }