Spring core xml (#2971)
* BAEL-1247 Spring XML injection. * BAEL-1247 - updated test * BAEL-1247 - updated test
This commit is contained in:
parent
e98ba8a321
commit
2f5370dea6
@ -5,7 +5,7 @@
|
||||
|
||||
<bean id="indexService" class="com.baeldung.di.spring.IndexService" />
|
||||
|
||||
<bean id="messageService" class="com.baeldung.di.spring.MessageService" scope="prototype">
|
||||
<bean id="messageService" class="com.baeldung.di.spring.MessageService">
|
||||
<constructor-arg value="${message.value}" />
|
||||
</bean>
|
||||
|
||||
@ -29,15 +29,15 @@
|
||||
<property name="service" ref="indexService" />
|
||||
</bean>
|
||||
|
||||
<bean id="indexAppWithStaticFactory" class="com.baeldung.di.spring.IndexApp" scope="prototype">
|
||||
<bean id="indexAppWithStaticFactory" class="com.baeldung.di.spring.IndexApp">
|
||||
<property name="service" ref="messageServiceFromStaticFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="indexAppWithFactoryMethod" class="com.baeldung.di.spring.IndexApp" scope="prototype">
|
||||
<bean id="indexAppWithFactoryMethod" class="com.baeldung.di.spring.IndexApp">
|
||||
<property name="service" ref="messageServiceFromInstanceFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="messageWorldApp" class="com.baeldung.di.spring.MessageApp" scope="prototype">
|
||||
<bean id="messageWorldApp" class="com.baeldung.di.spring.MessageApp">
|
||||
<constructor-arg ref="messageService" />
|
||||
</bean>
|
||||
</beans>
|
@ -15,31 +15,17 @@ public class BeanInjectionTest {
|
||||
applicationContext = new ClassPathXmlApplicationContext("com.baeldung.di.spring.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void protoBean_getBean_returnsMultipleInstance() {
|
||||
final MessageApp messageApp1 = applicationContext.getBean("messageWorldApp", MessageApp.class);
|
||||
final MessageApp messageApp2 = applicationContext.getBean("messageWorldApp", MessageApp.class);
|
||||
assertNotEquals(messageApp1, messageApp2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void protoFactoryMethod_getBean_returnsMultipleInstance() {
|
||||
final IndexApp indexApp1 = applicationContext.getBean("indexAppWithFactoryMethod", IndexApp.class);
|
||||
final IndexApp indexApp2 = applicationContext.getBean("indexAppWithFactoryMethod", IndexApp.class);
|
||||
assertNotEquals(indexApp1, indexApp2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void protoStaticFactory_getBean_returnsMultipleInstance() {
|
||||
final IndexApp indexApp1 = applicationContext.getBean("indexAppWithStaticFactory", IndexApp.class);
|
||||
final IndexApp indexApp2 = applicationContext.getBean("indexAppWithStaticFactory", IndexApp.class);
|
||||
assertNotEquals(indexApp1, indexApp2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singletonBean_getBean_returnsSingleInstance() {
|
||||
final IndexApp indexApp1 = applicationContext.getBean("indexApp", IndexApp.class);
|
||||
final IndexApp indexApp2 = applicationContext.getBean("indexApp", IndexApp.class);
|
||||
assertEquals(indexApp1, indexApp2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBean_returnsInstance() {
|
||||
final IndexApp indexApp = applicationContext.getBean("indexApp", IndexApp.class);
|
||||
assertNotNull(indexApp);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user