Skip to content

Commit

Permalink
Avoid startup bean processing warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
schnapster committed Jan 2, 2025
1 parent b7eaefe commit f019ad7
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ import net.ttddyy.dsproxy.listener.logging.DefaultQueryLogEntryCreator
import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel.WARN
import net.ttddyy.dsproxy.listener.logging.SLF4JSlowQueryListener
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder
import org.springframework.beans.factory.ObjectProvider
import org.springframework.beans.factory.config.BeanPostProcessor
import org.springframework.stereotype.Component

@Component
class DataSourceProxyPostProcessor(
queryCountHolder: SingleQueryCountHolder,
// Use ObjectProvider to avoid warnings about this bean being initialized too early for post processing
queryCountHolder: ObjectProvider<SingleQueryCountHolder>,
) : BeanPostProcessor {

private val proxyDataSourceBuilder = ProxyDataSourceBuilder()
.listener(buildSlf4jSlowQueryListener())
.multiline()
.name("postgres")
.countQuery(queryCountHolder)
private val proxyDataSourceBuilder by lazy {
ProxyDataSourceBuilder()
.listener(buildSlf4jSlowQueryListener())
.multiline()
.name("postgres")
.countQuery(queryCountHolder.getObject())
}

override fun postProcessAfterInitialization(bean: Any, beanName: String): Any? {
// if (bean is HikariDataSource) {
Expand Down

0 comments on commit f019ad7

Please sign in to comment.