BAEL-2399: Migrate Spring DI example to spring-core module

This commit is contained in:
eric-martin
2019-02-05 22:14:51 -06:00
parent 874acddfcf
commit 01fa4cfaf8
26 changed files with 129 additions and 78 deletions
@@ -0,0 +1,27 @@
package com.baeldung.di.spring;
import org.springframework.stereotype.Component;
@Component
public class Account {
private String accountNumber;
private String type;
public String getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
@@ -0,0 +1,5 @@
package com.baeldung.di.spring;
public interface AccountService {
}
@@ -0,0 +1,8 @@
package com.baeldung.di.spring;
import org.springframework.stereotype.Component;
@Component
public class AccountServiceImpl implements AccountService {
}
@@ -0,0 +1,5 @@
package com.baeldung.di.spring;
public interface AudioBookService {
}
@@ -0,0 +1,5 @@
package com.baeldung.di.spring;
public class AudioBookServiceImpl implements AudioBookService {
}
@@ -0,0 +1,5 @@
package com.baeldung.di.spring;
public interface AuthorService {
}
@@ -0,0 +1,5 @@
package com.baeldung.di.spring;
public class AuthorServiceImpl implements AuthorService {
}
@@ -0,0 +1,5 @@
package com.baeldung.di.spring;
public interface BookService {
}
@@ -0,0 +1,10 @@
package com.baeldung.di.spring;
import org.springframework.beans.factory.annotation.Autowired;
public class BookServiceImpl implements BookService {
@Autowired(required = false)
private AuthorService authorService;
}
@@ -0,0 +1,4 @@
package com.baeldung.di.spring;
public class Foo {
}
@@ -0,0 +1,6 @@
package com.baeldung.di.spring;
public class FooProcessor {
private Foo foo;
}
@@ -0,0 +1,5 @@
package com.baeldung.di.spring;
public interface PersonDao {
}
@@ -0,0 +1,8 @@
package com.baeldung.di.spring;
import org.springframework.stereotype.Component;
@Component
public class PersonDaoImpl implements PersonDao {
}
@@ -0,0 +1,14 @@
package com.baeldung.di.spring;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SpringBeansConfig {
@Bean
public AudioBookService audioBookServiceGenerator() {
return new AudioBookServiceImpl();
}
}
@@ -0,0 +1,18 @@
package com.baeldung.di.spring;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import({ SpringBeansConfig.class })
@ComponentScan("com.baeldung.di.spring")
public class SpringMainConfig {
@Bean
public BookService bookServiceGenerator() {
return new BookServiceImpl();
}
}
@@ -0,0 +1,20 @@
package com.baeldung.di.spring;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class SpringPersonService {
@Autowired
private PersonDao personDao;
public PersonDao getPersonDao() {
return personDao;
}
public void setPersonDao(PersonDao personDao) {
this.personDao = personDao;
}
}
@@ -0,0 +1,20 @@
package com.baeldung.di.spring;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class UserService {
@Autowired
private AccountService accountService;
public AccountService getAccountService() {
return accountService;
}
public void setAccountService(AccountService accountService) {
this.accountService = accountService;
}
}