Skip to content
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

关于Spring教程中第一章的《深入学习Spring组件注册》中的错误 #39

Open
chtzs opened this issue Mar 28, 2021 · 1 comment

Comments

@chtzs
Copy link

chtzs commented Mar 28, 2021

在Spring中的教程第一章深入学习Spring组件注册中,有这样的一段关于自定义过滤器的代码,声称可以过滤所有类名包含字符串er的类

public class MyTypeFilter implements TypeFilter {
    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) {
        // 获取当前正在扫描的类的注解信息
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
        // 获取当前正在扫描的类的类信息
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        // 获取当前正在扫描的类的路径等信息
        Resource resource = metadataReader.getResource();

        String className = classMetadata.getClassName();
        return StringUtils.hasText("er");
    }
}

但事实上

return StringUtils.hasText("er");

起不到任何过滤目标字符串的作用,这仅仅是个判断字符串是否为空串的函数。请作者修正~

@ruan4261
Copy link

盲生你发现了华点, XD

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

No branches or pull requests

2 participants