注解
@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 )
网友评论