빈의 스코프
싱글턴
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}@Component
public class AppRunner implements ApplicationRunner {
@Autowired
Single single;
@Autowired
Proto proto;
@Override
public void run(ApplicationArguments args) throws Exception {
// AppRunner가 불러오는 proto
System.out.println(proto);
// Single이 불러오는 proto
System.out.println(single.getProto());
}
}프로토타입
프로토타입 빈이 싱글턴 빈을 참조하는 경우
싱글턴 빈이 프로토타입 빈을 참조하는 경우
해결법
싱글턴 객체 사용 시 주의할 점
Last updated