spring-cloud-commons icon indicating copy to clipboard operation
spring-cloud-commons copied to clipboard

How to exclude a BootstrapConfiguration class ?

Open eacdy opened this issue 4 years ago • 1 comments

How to exclude a BootstrapConfiguration class ?

For example, There is a class in the spring.factories like below: (B.T.W This file is in a jar file which is made by other team.)

org.springframework.cloud.bootstrap.BootstrapConfiguration=com.bd.FooConfiguration

But I DO NOT want to use this com.bd.FooConfiguration, How Could I exclude it ?

Dive into source code, I found that @BootstrapConfiguration has a exclude attribute.

org.springframework.cloud.bootstrap.BootstrapConfiguration

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface BootstrapConfiguration {

	/**
	 * Excludes specific auto-configuration classes such that they will never be applied.
	 * @return classes to exclude
	 */
	Class<?>[] exclude() default {};

}

But when I use it like this:

@BootstrapConfiguration(exclude = {
        com.bytedance.ea.cloud.tcc.TccConfigBootstrapConfiguration.class
})
@SpringBootApplication
public class Cloud_SpringBoot2ExampleApplication {
    public static void main(String[] args) {
        SpringApplication.run(Cloud_SpringBoot2ExampleApplication.class, args);
    }
}

It never works. And I didn't find any usage or reference of the exclude attribute. image

So I wonder:

  1. How to exclude a specific class?
  2. Is the exclude attribute of @BootstrapConfiguration useless ? Cause I Cannot find any reference of it.

eacdy avatar Sep 16 '21 04:09 eacdy

up. I'd like to override PropertySourceBootstrapConfiguration and use my CustomPropertySourceBootstrapConfiguration. I need it to change priority between external application.properties, "in jar" application.properties and remote properties like this:

1. external application.properties
2. remote properties
3. application.properties from the JAR (classpath)

So, I've added CustomPropertySourceBootstrapConfiguration to BootstrapConfiguration in spring.factories and now I can't to exclude original PropertySourceBootstrapConfiguration from start up process.

S1lash avatar Jun 08 '22 21:06 S1lash