JAVA-959: Migrate spring-di to com.baeldung

This commit is contained in:
Krzysiek 2020-03-11 21:09:04 +01:00
parent 5a9ac3ce57
commit 6906bb047d
9 changed files with 50 additions and 50 deletions

View File

@ -1,4 +1,4 @@
package org.baeldung.store; package com.baeldung.store;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;

View File

@ -1,4 +1,4 @@
package org.baeldung.store; package com.baeldung.store;
public interface Item { public interface Item {

View File

@ -1,4 +1,4 @@
package org.baeldung.store; package com.baeldung.store;
public class ItemImpl1 implements Item { public class ItemImpl1 implements Item {

View File

@ -1,4 +1,4 @@
package org.baeldung.store; package com.baeldung.store;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@ -6,9 +6,9 @@
<!-- Autowired injection --> <!-- Autowired injection -->
<bean id="item" class="org.baeldung.store.ItemImpl1" /> <bean id="item" class="com.baeldung.store.ItemImpl1" />
<bean id="xml-store-by-autowire-type" class="org.baeldung.store.Store" autowire="byType"> <bean id="xml-store-by-autowire-type" class="com.baeldung.store.Store" autowire="byType">
</bean> </bean>
</beans> </beans>

View File

@ -6,28 +6,28 @@
<!-- Constructor injection --> <!-- Constructor injection -->
<bean id="item1" class="org.baeldung.store.ItemImpl1" /> <bean id="item1" class="com.baeldung.store.ItemImpl1" />
<bean id="xml-store-by-constructor" class="org.baeldung.store.Store"> <bean id="xml-store-by-constructor" class="com.baeldung.store.Store">
<constructor-arg type="Item" index="0" name="item" ref="item1" /> <constructor-arg type="Item" index="0" name="item" ref="item1" />
</bean> </bean>
<!-- Setter injection --> <!-- Setter injection -->
<bean id="xml-store-by-setter" class="org.baeldung.store.Store"> <bean id="xml-store-by-setter" class="com.baeldung.store.Store">
<property name="item" ref="item1" /> <property name="item" ref="item1" />
</bean> </bean>
<!-- Autowired injection --> <!-- Autowired injection -->
<bean id="item" class="org.baeldung.store.ItemImpl1" /> <bean id="item" class="com.baeldung.store.ItemImpl1" />
<bean id="xml-store-by-autowire-name" class="org.baeldung.store.Store" autowire="byName"> <bean id="xml-store-by-autowire-name" class="com.baeldung.store.Store" autowire="byName">
</bean> </bean>
<!-- Lazy instantiation --> <!-- Lazy instantiation -->
<bean id="item1-lazy" class="org.baeldung.store.ItemImpl1" lazy-init="true" /> <bean id="item1-lazy" class="com.baeldung.store.ItemImpl1" lazy-init="true" />
<bean id="xml-store-by-setter-lazy" class="org.baeldung.store.Store"> <bean id="xml-store-by-setter-lazy" class="com.baeldung.store.Store">
<property name="item" ref="item1-lazy" /> <property name="item" ref="item1-lazy" />
</bean> </bean>

View File

@ -1,35 +1,35 @@
package org.baeldung.store; package com.baeldung.store;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class) @ContextConfiguration(classes = AppConfig.class)
public class AppConfigUnitTest { public class AppConfigUnitTest {
@Autowired @Autowired
@Qualifier("storeThroughConstructorInjection") @Qualifier("storeThroughConstructorInjection")
private Store storeByConstructorInjection; private Store storeByConstructorInjection;
@Autowired @Autowired
@Qualifier("storeThroughSetterInjection") @Qualifier("storeThroughSetterInjection")
private Store storeBySetterInjection; private Store storeBySetterInjection;
@Test @Test
public void givenValidXmlConfig_WhenInjectStoreByConstructorInjection_ThenBeanIsNotNull() { public void givenValidXmlConfig_WhenInjectStoreByConstructorInjection_ThenBeanIsNotNull() {
assertNotNull(storeByConstructorInjection); assertNotNull(storeByConstructorInjection);
assertNotNull(storeByConstructorInjection.getItem()); assertNotNull(storeByConstructorInjection.getItem());
} }
@Test @Test
public void givenValidXmlConfig_WhenInjectStoreBySetterInjection_ThenBeanIsNotNull() { public void givenValidXmlConfig_WhenInjectStoreBySetterInjection_ThenBeanIsNotNull() {
assertNotNull(storeBySetterInjection); assertNotNull(storeBySetterInjection);
assertNotNull(storeByConstructorInjection.getItem()); assertNotNull(storeByConstructorInjection.getItem());
} }
} }

View File

@ -1,4 +1,4 @@
package org.baeldung.store; package com.baeldung.store;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;

View File

@ -1,4 +1,4 @@
package org.baeldung.store; package com.baeldung.store;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;