|
@@ -6,15 +6,17 @@ import cn.tonyandmoney.tuon.core.properties.CustomConfigProperties
|
|
import com.fasterxml.jackson.databind.ObjectMapper
|
|
import com.fasterxml.jackson.databind.ObjectMapper
|
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
|
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
|
|
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
|
|
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
|
|
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
|
|
|
+import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
|
|
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.context.annotation.Primary
|
|
import org.springframework.context.annotation.Primary
|
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
|
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
|
|
|
|
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
|
|
|
|
+import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter
|
|
import org.springframework.web.server.WebFilter
|
|
import org.springframework.web.server.WebFilter
|
|
-import reactor.core.publisher.Flux
|
|
|
|
import java.text.SimpleDateFormat
|
|
import java.text.SimpleDateFormat
|
|
|
|
|
|
|
|
|
|
@@ -25,25 +27,31 @@ import java.text.SimpleDateFormat
|
|
@EnableConfigurationProperties(value = [CustomConfigProperties::class])
|
|
@EnableConfigurationProperties(value = [CustomConfigProperties::class])
|
|
class CustomCoreConfiguration {
|
|
class CustomCoreConfiguration {
|
|
|
|
|
|
|
|
+ companion object {
|
|
|
|
+ const val CONVERTER_NAME = "hookMappingJackson2HttpMessageConverter"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 跨域配置,Reactive
|
|
|
|
+ */
|
|
@Bean
|
|
@Bean
|
|
- @ConditionalOnProperty(prefix = "custom.config.enable", name = ["cros"], havingValue = "true", matchIfMissing = true)
|
|
|
|
- @ConditionalOnClass(Flux::class)
|
|
|
|
|
|
+ @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
|
|
|
|
+ @ConditionalOnProperty(prefix = CustomConfigProperties.CROS_PREFIX, name = ["enable"], havingValue = "true", matchIfMissing = true)
|
|
fun fluxCrosFilter(): WebFilter {
|
|
fun fluxCrosFilter(): WebFilter {
|
|
return GlobalCrosFilter()
|
|
return GlobalCrosFilter()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * servlet跨域配置
|
|
|
|
+ */
|
|
@Bean
|
|
@Bean
|
|
- @ConditionalOnProperty(prefix = "custom.config.enable", name = ["cros"], havingValue = "true", matchIfMissing = true)
|
|
|
|
|
|
+ @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
|
|
|
+ @ConditionalOnProperty(prefix = CustomConfigProperties.CROS_PREFIX, name = ["enable"], havingValue = "true", matchIfMissing = true)
|
|
fun crosFilter(): GlobalWebCrosFilter {
|
|
fun crosFilter(): GlobalWebCrosFilter {
|
|
return GlobalWebCrosFilter()
|
|
return GlobalWebCrosFilter()
|
|
}
|
|
}
|
|
|
|
|
|
- @Bean("xmlObjectMapper")
|
|
|
|
- fun xmlObjectMapper(): ObjectMapper {
|
|
|
|
- return Jackson2ObjectMapperBuilder.xml().build()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
@Primary
|
|
@Primary
|
|
@@ -68,5 +76,31 @@ class CustomCoreConfiguration {
|
|
return mapper
|
|
return mapper
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * XML解析和生成
|
|
|
|
+ */
|
|
|
|
+ @Bean("xmlObjectMapper")
|
|
|
|
+ fun xmlObjectMapper(): ObjectMapper {
|
|
|
|
+ return Jackson2ObjectMapperBuilder.xml().build()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Bean(CONVERTER_NAME)
|
|
|
|
+ fun getConverter(objectMapper: ObjectMapper): MappingJackson2HttpMessageConverter {
|
|
|
|
+ return MappingJackson2HttpMessageConverter().apply {
|
|
|
|
+ this.objectMapper = objectMapper
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 解析XML转换器,不知道能否成功
|
|
|
|
+ */
|
|
|
|
+ @Bean
|
|
|
|
+ fun xmlConverter(@Qualifier("xmlObjectMapper") objectMapper: ObjectMapper): MappingJackson2XmlHttpMessageConverter {
|
|
|
|
+ return MappingJackson2XmlHttpMessageConverter().apply {
|
|
|
|
+ this.objectMapper = objectMapper
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|