Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- http
- QueryDSL
- spring
- Android
- Exception
- 인프런
- Greedy
- Spring Boot
- springdatajpa
- Thymeleaf
- 자바
- 스프링 핵심 기능
- 스프링
- 김영한
- SpringBoot
- pointcut
- JPQL
- AOP
- transaction
- Servlet
- jpa
- Proxy
- JDBC
- java
- 그리디
- 알고리즘
- kotlin
- 백준
- 스프링 핵심 원리
- db
Archives
- Today
- Total
개발자되기 프로젝트
[빈 후처리기] 예제코드 1 - 일반적인 스프링 빈 등록 본문
1. 일반적인 스프링 빈 등록
public class BasicTest {
@Test
void basicConfig (){
//스프링 컨테이너
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(BasicConfig.class);
//A는 빈으로 등록됨.
A a = applicationContext.getBean("beanA", A.class);
a.helloA();
//B는 스프링 빈으로 등록되지 않음.
Assertions.assertThrows(NoSuchBeanDefinitionException.class, () -> applicationContext.getBean(B.class));
}
@Slf4j
@Configuration
static class BasicConfig{
@Bean(name= "beanA")
public A a(){
return new A();
}
}
@Slf4j
static class A {
public void helloA(){
log.info("hello A");
}
}
@Slf4j
static class B {
public void helloB(){
log.info("hello B");
}
}
}
- new AnnotationConfigApplicationContext(BasicConfig.class)
- 스프링 컨테이너를 생성하면서 BasicConfig.class 를 넘겨주었다.
- BasicConfig.class 설정 파일은 스프링 빈으로 등록된다.
BeanFactory와 ApplicationContext
1. BeanFactory 스프링 컨테이너의 최상위 인터페이스 = 가장 기초적인 스프링 컨테이너의 역할? 스프링 빈을 관리하고 조회하는 역할 getBean() 제공 2. ApplicationContext BeanFactory기능을 모두 상속받음 그
bsh-developer.tistory.com
- A a = applicationContext.getBean("beanA", A.class)
- beanA 라는 이름으로 A 타입의 스프링 빈을 찾을 수 있다.
- applicationContext.getBean(B.class)
- B 타입의 객체는 스프링 빈으로 등록한 적이 없기 때문에 스프링 컨테이너에서 찾을 수 없다.
2. GitHub : 220102 Bean Post Processor
GitHub - bsh6463/Spring_Advanced_2
Contribute to bsh6463/Spring_Advanced_2 development by creating an account on GitHub.
github.com
'인프런 > [인프런] 스프링 핵심 원리 - 고급' 카테고리의 다른 글
[빈 후처리기] Bean Post Processor 적용 (0) | 2022.01.02 |
---|---|
[빈 후처리기] 예제코드 2 - 객체 바꿔치기 (0) | 2022.01.02 |
[빈 후처리기] Bean Post Processor - 소개 (0) | 2022.01.02 |
프록시팩토리- 정리 (0) | 2022.01.01 |
프록시팩토리 - 적용 2 (0) | 2022.01.01 |
Comments