spring-cloud / spring-cloud/spring-cloud-commons

How to exclude a BootstrapConfiguration class ?

Open
#1,008 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
Dominant language
Java
Stars
751
Forks
744
Avg merge
1d 14h
Merged PRs (30d)
9

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with org.springframework.cloud.bootstrap.BootstrapConfiguration and the spring.factories entry shown in the report, then trace whether the annotation's exclude attribute is read anywhere. Document the supported way to exclude com.bd.FooConfiguration and clarify whether the exclude attribute is effective, including a focused verification if the repository provides a relevant test entry point.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
backend
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.