Last active
April 30, 2020 02:40
-
-
Save djkeh/6194d9123256042be06c6df72a3a3e58 to your computer and use it in GitHub Desktop.
프로토타입 빈 + InjectionPoint를 이용한 최신 스프링 Logger 주입 예제 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 스프링 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()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
public class SampleController { | |
private final Logger logger; | |
public SampleController(Logger logger) { | |
this.logger = logger; | |
} | |
public void controllerMethod() { | |
logger.info("LOG!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
이 코드는 spring-projects/spring-boot#8106 에서 논의되었고, 이 코드가 가져오는 이득이 크지 않은 것으로 판단되어 스프링 부트 삽입에 채택되지 않았습니다.