java - spring自动扫描context:component-scan的简单问题

查看:113
本文介绍了java - spring自动扫描context:component-scan的简单问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

<context:component-scan base-package="personal.test" use-default-filters="false" >
        <context:include-filter type="regex" expression="personal.test.manager.*"/>
        <context:include-filter type="regex" expression="personal.test.apiserver.process.sdkapi.*"/>
    </context:component-scan>

我看都说<context:component-scan>这个扫描,只会扫描@Component @Controller@Service等这些注解的类。

可是,我上面的配置,personal.test.manager这个包下的所有类都被实例化了。

很多类并没有加注解。

我怎样设置才能只扫面@Component @Controller@Service等这些注解的类呢?

小白一个,谢谢各位大神帮忙解答一下了。

解决方案

type 不要用 regex, 使用 annotation

<context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />

这篇关于java - spring自动扫描context:component-scan的简单问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆