JAVA-959: Migrate spring-di to com.baeldung
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.store;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
public class AppConfig {
|
||||
|
||||
@Bean
|
||||
public Item item1() {
|
||||
return new ItemImpl1();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Store storeThroughConstructorInjection() {
|
||||
return new Store(item1());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Store storeThroughSetterInjection() {
|
||||
Store store = new Store();
|
||||
store.setItem(item1());
|
||||
return store;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.baeldung.store;
|
||||
|
||||
public interface Item {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.baeldung.store;
|
||||
|
||||
public class ItemImpl1 implements Item {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.store;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class Store {
|
||||
|
||||
@Autowired
|
||||
private Item item;
|
||||
|
||||
public Store() {}
|
||||
|
||||
public Store(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user