美文网首页
Spring(五)Bean装配之Autowired注解

Spring(五)Bean装配之Autowired注解

作者: lqsss | 来源:发表于2018-03-22 15:23 被阅读0次

注解

@Scope
@Component
public class BeanAnnotation {
    
    public void say(String arg) {
        System.out.println("BeanAnnotation : " + arg);
    }
    
    public void myHashCode() {
        System.out.println("BeanAnnotation : " + this.hashCode());
    }
    
}

配置

<context:component-scan base-package="com.imooc.beanannotation"></context:component-scan>

扫描目录,寻找有注解的类,生成bean放入容器中

测试

public void testSay() {
        BeanAnnotation bean = super.getBean("beanAnnotation");
        bean.say("This is test.");

@Component没有指定名称的话,id就是类的第一个字母小写(beanAnnotation )

相关文章

网友评论

      本文标题:Spring(五)Bean装配之Autowired注解

      本文链接:https://www.haomeiwen.com/subject/vppaqftx.html