I have a configuration class and a test class as below:
@Configuration
public class SimpleConfiguration {
@Bean
@Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public String hello() {
return "hello";
}
}
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = SimpleConfiguration.class)
public class SimpleTest {
@Autowired
private String hello;
@Autowired
private String another;
@Test
public void should_not_same() {
Assert.assertNotSame(hello, another);
}
}
According to the definition of prototype scope
, the hello
and another
object should be not same, but this test failed. Why? Thanks!