@Configuration
346
작성한 질문수 4
안녕하세요 선생님,
수업 pdf 75페이지 @Configuration 질문입니다.
여기서 TestConfig 클래스는 @Configuration 어노테이션을 붙이지 않아도 new AnnotationConfigApplicationContext에서 구성정보로 잘 들어가는데, 왜 안붙여도 정상작동 하나요?
@Configuration 어노테이션을 붙이지 않는 이유가 있을까요?
package hello.core.singleton;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
public class StatefulServiceTest {
@Test
void statefulServiceSingleton() {
ApplicationContext ac = new AnnotationConfigApplicationContext(TestConfig.class);
StatefulService statefulService1 = ac.getBean("statefulService", StatefulService.class);
StatefulService statefulService2 = ac.getBean("statefulService", StatefulService.class);
//ThreadA: A사용자 10000원 주문
statefulService1.order("userA", 10000);
//ThreadB: B사용자 20000원 주문
statefulService2.order("userB", 20000);
//ThreadA: 사용자A 주문 금액 조회
int price = statefulService1.getPrice();
//ThreadA: 사용자A는 10000원을 기대했지만, 기대와 다르게 20000원 출력
System.out.println("price = " + price);
Assertions.assertThat(statefulService1.getPrice()).isEqualTo(20000);
}
static class TestConfig {
@Bean
public StatefulService statefulService() {
return new StatefulService();
}
}
}
답변 1
0
안녕하세요. 피엔님
다음 질문을 참고해주세요^^
https://www.inflearn.com/questions/191114
https://www.inflearn.com/questions/186890
감사합니다.
SingletonService가 JVM이 뜰 때 생성되는게 맞나요?
0
15
1
섹션3. 11 회원객체 다이어그램
0
36
1
OCP, DIP과 @Qualifier 어노테이션에 대해서 질문합니다.
0
35
1
코드 자료
0
80
2
구현체가 동적으로 정해질 때, 팩토리 기법을 사용하나요?
0
79
2
MemberService의 인터페이스를 왜 사용하는지 궁금합니다.
0
97
1
롬복 @Setter를 써야 하는 상황이 있는건가요?
0
103
1
빈 등록 메서드의 파라미터가 빈이 아니어도 되나요?
0
88
1
테스트 속도가 나중에 영향이 있을까요?
0
89
1
gradle 설정 안떠서 질문 남깁니다!
0
137
2
build.gradle로 프로젝트를 여는 이유
0
100
1
provider 사용하는 이유
0
97
1
다음 강의 뭘 들어야 할까요
0
138
2
프로토타입 빈, 직접 destroy 호출 안 할 경우
0
69
1
beanB
0
90
2
퀴즈다시풀기
0
73
1
Gradle로 바꿔도 오류가 똑같이 발생하네요 ㅠㅠ
0
102
2
"중복 등록과 충돌" 강의에서 강사님과 다른 에러가 발생합니다.
0
70
3
run 실행했는데 결과창이 이렇게 뜨네요 왜 그런건가요>
0
111
2
도메인의 정의?
0
63
1
ApplicationContext 질문입니다.
0
68
1
@Scope의 proxyMode를 사용할때 단위 테스트 방법
0
97
2
ai api 선정하기 관련 질문
0
132
2
생성자 자동주입 관련해서
0
68
1





