4.1節當中我將Scope改成了prototype,為啥返回的還是同一對象?
package?com.imooc.test.beanannotation;
import?org.junit.Test;
import?org.junit.runner.RunWith;
import?org.junit.runners.BlockJUnit4ClassRunner;
import?com.imooc.beanannotation.BeanAnnotation;
import?com.imooc.test.base.UnitTestBase;
@RunWith(BlockJUnit4ClassRunner.class)
public?class?TestBeanAnnotation?extends?UnitTestBase?{
public?TestBeanAnnotation()?{
super("classpath*:spring-beanannotation.xml");
}
@Test
public?void?testScpoe()?{
BeanAnnotation?bean?=?super.getBean("beanAnnotation");
bean.myHashCode();
bean?=?super.getBean("beanAnnotation");
bean.myHashCode();
}
}package?com.imooc.beanannotation;
import?org.springframework.context.annotation.Scope;
import?org.springframework.stereotype.Component;
//@Component("bean")
@Scope("prototype")
@Component
public?class?BeanAnnotation?{
public?void?myHashCode()?{
System.out.println("BeanAnnotation?:?"?+?this.hashCode());
}
}兩個bean輸出的hashcode是一樣的
BeanAnnotation?:?2039473569 BeanAnnotation?:?2039473569
2017-09-10
應該是對一個store子類@scope(value)吧