Skip to content

Commit

Permalink
perf: @bean初始化优化, 以消除:is not eligible for getting processed by all Be…
Browse files Browse the repository at this point in the history
…anPostProcessors (#608)

1. 由于Advisor会优先初始化,故相关@bean应加: @ROLE(BeanDefinition.ROLE_INFRASTRUCTURE)
以消除:is not eligible for getting processed by all BeanPostProcessors

2. 去除@EnableConfigurationProperties(DynamicDataSourceProperties.class) 改为static方式配置是为了加@ROLE(BeanDefinition.ROLE_INFRASTRUCTURE)

3. spring 5.2+ 配置类如不内部不存在@bean方法引用应加: proxyBeanMethods = false 以去除不必要代理类
 ie: `@Configuration(proxyBeanMethods = false)`

此PR是了消除启动时的以下日志:

```
 [restartedMain] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker[376] - Bean 'spring.datasource.dynamic-com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties' of type [com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
12-23 09:29:16.779 [restartedMain] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker[376] - Bean 'dsProcessor' of type [com.baomidou.dynamic.datasource.processor.DsHeaderProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
```
  • Loading branch information
qxo authored Jan 2, 2024
1 parent 921d61a commit b6d2595
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.baomidou.dynamic.datasource.tx.DsTxEventListenerFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
Expand All @@ -44,7 +43,6 @@
*/
@Configuration
@RequiredArgsConstructor
@EnableConfigurationProperties(DynamicDataSourceProperties.class)
public class DynamicDataSourceAssistConfiguration {

private final DynamicDataSourceProperties properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
Expand All @@ -47,8 +46,8 @@
* @see DynamicRoutingDataSource
* @since 1.0.0
*/
@Configuration
@EnableConfigurationProperties(DynamicDataSourceProperties.class)
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Configuration(proxyBeanMethods = false)
public class DynamicDataSourceAopConfiguration {

private final DynamicDataSourceProperties properties;
Expand All @@ -57,6 +56,13 @@ public DynamicDataSourceAopConfiguration(DynamicDataSourceProperties properties)
this.properties = properties;
}

@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Bean
public static DynamicDataSourceProperties dynamicDataSourceProperties() {
return new DynamicDataSourceProperties();
}

@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Bean
@ConditionalOnMissingBean
public DsProcessor dsProcessor(BeanFactory beanFactory) {
Expand All @@ -69,7 +75,6 @@ public DsProcessor dsProcessor(BeanFactory beanFactory) {
return headerProcessor;
}


@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Bean
@ConditionalOnProperty(prefix = DynamicDataSourceProperties.PREFIX + ".aop", name = "enabled", havingValue = "true", matchIfMissing = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand All @@ -45,7 +44,6 @@
*/
@Slf4j
@Configuration
@EnableConfigurationProperties(DynamicDataSourceProperties.class)
@AutoConfigureBefore(value = DataSourceAutoConfiguration.class, name = "com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure")
@Import({DruidDynamicDataSourceConfiguration.class, DynamicDataSourceCreatorAutoConfiguration.class, DynamicDataSourceAopConfiguration.class, DynamicDataSourceAssistConfiguration.class})
@ConditionalOnProperty(prefix = DynamicDataSourceProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
Expand All @@ -47,8 +46,7 @@
* @see DynamicRoutingDataSource
* @since 1.0.0
*/
@Configuration
@EnableConfigurationProperties(DynamicDataSourceProperties.class)
@Configuration(proxyBeanMethods = false)
public class DynamicDataSourceAopConfiguration {

private final DynamicDataSourceProperties properties;
Expand All @@ -57,6 +55,13 @@ public DynamicDataSourceAopConfiguration(DynamicDataSourceProperties properties)
this.properties = properties;
}

@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Bean
public static DynamicDataSourceProperties dynamicDataSourceProperties() {
return new DynamicDataSourceProperties();
}

@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Bean
@ConditionalOnMissingBean
public DsProcessor dsProcessor(BeanFactory beanFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
* @since 1.0.0
*/
@Slf4j
@Configuration
@EnableConfigurationProperties(DynamicDataSourceProperties.class)
@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore(
value = DataSourceAutoConfiguration.class,
name = {
Expand Down

0 comments on commit b6d2595

Please sign in to comment.