Skip to content

修改 spring 八股中的注释逻辑错误 #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

4Nanai
Copy link

@4Nanai 4Nanai commented Jul 31, 2025

错误出处

34.🌟SpringBoot 自动配置原理了解吗?
getAutoConfigurationEntry() 方法的源码注释

    // 检查排除的类是否存在于候选配置中,如果存在,则抛出异常。
    checkExcludedClasses(configurations, exclusions);

根据源码:

    private void checkExcludedClasses(List<String> configurations, Set<String> exclusions) {
        List<String> invalidExcludes = new ArrayList(exclusions.size());

        for(String exclusion : exclusions) {
            // 这里是在检测exclusion类存在且没有出现在configurations中
            if (ClassUtils.isPresent(exclusion, this.getClass().getClassLoader()) && !configurations.contains(exclusion)) {
                invalidExcludes.add(exclusion);
            }
        }

        if (!invalidExcludes.isEmpty()) {
            this.handleInvalidExcludes(invalidExcludes);
        }
    }

    protected void handleInvalidExcludes(List<String> invalidExcludes) {
        StringBuilder message = new StringBuilder();

        for(String exclude : invalidExcludes) {
            message.append("\t- ").append(exclude).append(String.format("%n"));
        }

        throw new IllegalStateException(String.format("The following classes could not be excluded because they are not auto-configuration classes:%n%s", message));
    }

这里是在check需要排除的类存在,但是不在候选配置中的情况。

修改

将原注释:
//检查排除的类是否存在于候选配置中,如果存在,则抛出异常
修改为:
// 检查排除的类是否出现在候选配置中,如果需要排除的类存在但没有出现在候选配置中,则抛出异常。

根据源码,这里是在check需要排除的类存在,但是不在候选配置中的情况。而不是原文描述的“检查排除的类是否存在于候选配置中,如果存在,则抛出异常“。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant