Skip to content

Instantly share code, notes, and snippets.

@djkeh
Last active April 30, 2020 02:40
Show Gist options
  • Save djkeh/6194d9123256042be06c6df72a3a3e58 to your computer and use it in GitHub Desktop.
Save djkeh/6194d9123256042be06c6df72a3a3e58 to your computer and use it in GitHub Desktop.
프로토타입 빈 + InjectionPoint를 이용한 최신 스프링 Logger 주입 예제 코드
// 스프링 4.3부터 추가된 InjectionPoint를 이용한 Context-Aware Bean 생성 방법.
@Configuration
public class BeanConfig {
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
Logger logger(InjectionPoint injectionPoint) {
return LoggerFactory.getLogger(injectionPoint.getMethodParameter().getContainingClass());
}
}
@Controller
public class SampleController {
private final Logger logger;
public SampleController(Logger logger) {
this.logger = logger;
}
public void controllerMethod() {
logger.info("LOG!");
}
}
@djkeh
Copy link
Author

djkeh commented Apr 19, 2018

이 코드는 spring-projects/spring-boot#8106 에서 논의되었고, 이 코드가 가져오는 이득이 크지 않은 것으로 판단되어 스프링 부트 삽입에 채택되지 않았습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment