zoukankan      html  css  js  c++  java
  • 【Spring】10、Spring中用@Component、@Repository、@Service和 @Controller等标注的默认Bean名称会是小写开头的非限定类名

    @Service用于标注业务层组件(我们通常定义的service层就用这个)

    @Controller用于标注控制层组件(如struts中的action)

    @Repository用于标注数据访问组件,即DAO组件

    @Component泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。

    使用过滤器自定义扫描 <context:component-scan base-package="org.example"> 
    spring开发手册中这样写: 
    3.12.4. 自动检测组件的命名

    当一个组件在某个扫描过程中被自动检测到时,会根据那个扫描器的BeanNameGenerator 策略生成它的bean名称。默认情况下,任何包含 name值的Spring“典型”注解 (@Component、@Repository、 @Service和@Controller) 会把那个名字 提供给相关的bean定义。如果这个注解不包含name值或是其他检测到的组件 (比如被自定义过滤器发现的),默认bean名称生成器会返回小写开头的非限定(non-qualified)类名。 例如,如果发现了下面这两个组件,它们的名字会是‘myMovieLister‘和‘movieFinderImpl‘:

    @Service("myMovieLister")
    public class SimpleMovieLister {
        // ...
    }
    @Repository
    public class MovieFinderImpl implements MovieFinder {
        // ...
    }
  • 相关阅读:
    1363:小球(drop)
    ifstream ofstream c++中读写文件
    线性筛
    Network of Schools POJ
    Beautiful numbers CodeForces
    ipone6界面设计标准
    目前的前端框架有哪些
    什么是react native
    nth-child() 选择器
    html{height:100%}的意义以及body背景色的解析推断
  • 原文地址:https://www.cnblogs.com/wangzhongqiu/p/6648025.html
Copyright © 2011-2022 走看看