+3
-1
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile Jackson3AutoConfiguration.kt
|
||||
* LastUpdate 2026-03-11 08:46:40
|
||||
* LastUpdate 2026-10-02 16:11:12
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.mingliqiye.utils.json.converters.base.getJackson3Module
|
||||
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer
|
||||
import org.springframework.context.annotation.Bean
|
||||
|
||||
@@ -38,6 +39,7 @@ open class Jackson3AutoConfiguration {
|
||||
private val logger = MingLiLoggerFactory.getLogger<Jackson3AutoConfiguration>()
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(JsonMapperBuilderCustomizer::class)
|
||||
open fun myJsonMapperCustomizer(): JsonMapperBuilderCustomizer {
|
||||
return JsonMapperBuilderCustomizer { builder ->
|
||||
builder
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile Jackson3JsonApiAutoConfiguration.kt
|
||||
* LastUpdate 2026-06-21 10:40:58
|
||||
* LastUpdate 2026-10-02 16:11:02
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -39,7 +39,7 @@ open class Jackson3JsonApiAutoConfiguration {
|
||||
private val logger = MingLiLoggerFactory.getLogger<Jackson3JsonApiAutoConfiguration>()
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnMissingBean(JsonApi::class)
|
||||
open fun jsonApi(jsonMapper: JsonMapper): JsonApi {
|
||||
return Jackson3JsonApi(
|
||||
get = { jsonMapper },
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile JacksonAutoConfiguration.kt
|
||||
* LastUpdate 2026-03-11 08:46:40
|
||||
* LastUpdate 2026-10-02 16:10:53
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -91,7 +91,7 @@ open class JacksonAutoConfiguration(objectMapper: ObjectMapper) {
|
||||
*/
|
||||
@Bean
|
||||
@Primary
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnMissingBean(JsonApi::class)
|
||||
open fun jsonApi(objectMapper: ObjectMapper): JsonApi {
|
||||
return JacksonJsonApi(objectMapper).also {
|
||||
log.info("JsonApi Bean Auto Configuration Success")
|
||||
|
||||
+5
-3
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile Okhttp3AutoConfiguration.kt
|
||||
* LastUpdate 2026-02-27 17:40:32
|
||||
* LastUpdate 2026-10-02 16:10:15
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.slf4j.Logger
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.event.ContextClosedEvent
|
||||
import org.springframework.context.event.EventListener
|
||||
@@ -43,14 +44,15 @@ open class Okhttp3AutoConfiguration {
|
||||
open var userDefinedBuilder: okhttp3.OkHttpClient.Builder? = null
|
||||
|
||||
open fun initOkHttpClient() {
|
||||
if (userDefinedBuilder == null) {
|
||||
okHttpClient = okhttp3.OkHttpClient()
|
||||
okHttpClient = if (userDefinedBuilder == null) {
|
||||
okhttp3.OkHttpClient()
|
||||
} else {
|
||||
userDefinedBuilder!!.build()
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
open fun okHttpClient(): okhttp3.OkHttpClient {
|
||||
if (okHttpClient == null) {
|
||||
initOkHttpClient()
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile SpringBeanUtils.kt
|
||||
* LastUpdate 2026-02-26 14:09:02
|
||||
* LastUpdate 2026-10-02 16:18:14
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -25,6 +25,7 @@ package com.mingliqiye.utils.springboot.bean
|
||||
import org.springframework.beans.BeansException
|
||||
import org.springframework.context.ApplicationContext
|
||||
import org.springframework.context.ApplicationContextAware
|
||||
import org.springframework.context.ApplicationContextException
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
/**
|
||||
@@ -37,7 +38,12 @@ class SpringBeanUtils : ApplicationContextAware {
|
||||
companion object {
|
||||
|
||||
@JvmStatic
|
||||
private var applicationContext: ApplicationContext? = null
|
||||
val applicationContext: ApplicationContext
|
||||
get() = applicationContextBase
|
||||
?: throw ApplicationContextException("applicationContext isn't ContextInitialized ?")
|
||||
|
||||
private var applicationContextBase: ApplicationContext? = null
|
||||
|
||||
|
||||
@Throws(BeansException::class)
|
||||
inline fun <reified T : Any> getBean() = getBean(T::class.java)
|
||||
@@ -53,7 +59,7 @@ class SpringBeanUtils : ApplicationContextAware {
|
||||
@JvmStatic
|
||||
@Throws(BeansException::class)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun getBean(name: String): Any = applicationContext!!.getBean(name)
|
||||
fun getBean(name: String): Any = applicationContext.getBean(name)
|
||||
|
||||
/**
|
||||
* 根据Bean类型获取Bean实例
|
||||
@@ -65,7 +71,7 @@ class SpringBeanUtils : ApplicationContextAware {
|
||||
@JvmStatic
|
||||
@Throws(BeansException::class)
|
||||
fun <T : Any> getBean(clazz: Class<T>): T {
|
||||
return applicationContext!!.getBean(clazz)
|
||||
return applicationContext.getBean(clazz)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +85,7 @@ class SpringBeanUtils : ApplicationContextAware {
|
||||
@JvmStatic
|
||||
@Throws(BeansException::class)
|
||||
fun <T : Any> getBean(name: String, clazz: Class<T>): T {
|
||||
return applicationContext!!.getBean<T>(name, clazz)
|
||||
return applicationContext.getBean<T>(name, clazz)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +98,6 @@ class SpringBeanUtils : ApplicationContextAware {
|
||||
*/
|
||||
@Throws(BeansException::class)
|
||||
override fun setApplicationContext(applicationContext: ApplicationContext) {
|
||||
SpringBeanUtils.applicationContext = applicationContext
|
||||
applicationContextBase = applicationContext
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user