4.1節(jié)當(dāng)中我將Scope改成了prototype,為啥返回的還是同一對(duì)象?
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()); } }
兩個(gè)bean輸出的hashcode是一樣的
BeanAnnotation?:?2039473569 BeanAnnotation?:?2039473569
2017-09-10
應(yīng)該是對(duì)一個(gè)store子類@scope(value)吧