星辰Iron
2017-09-09 20:59
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
应该是对一个store子类@scope(value)吧
Spring入门篇
268787 学习 · 963 问题
相似问题