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;

View File

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

View File

@ -1,4 +1,4 @@
package org.baeldung.store;
package com.baeldung.store;
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;

View File

@ -6,9 +6,9 @@
<!-- 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>
</beans>

View File

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

View File

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

View File

@ -1,4 +1,4 @@
package org.baeldung.store;
package com.baeldung.store;
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;