From c9b0a62375b37e356ab8ba81ea34c352ec96c390 Mon Sep 17 00:00:00 2001 From: mjkhan21 Date: Fri, 6 Oct 2023 10:41:45 +0900 Subject: [PATCH] =?UTF-8?q?getBean(..)=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xit/foundation/ApplicationContainer.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/cokr/xit/foundation/ApplicationContainer.java b/src/main/java/cokr/xit/foundation/ApplicationContainer.java index 48684f5..ba1beb2 100644 --- a/src/main/java/cokr/xit/foundation/ApplicationContainer.java +++ b/src/main/java/cokr/xit/foundation/ApplicationContainer.java @@ -3,6 +3,7 @@ package cokr.xit.foundation; import java.net.InetAddress; import java.util.Date; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -83,6 +84,21 @@ public class ApplicationContainer implements ApplicationContextAware { return actx; } + /**지정한 이름과 클래스의 Bean을 반환한다. + * @param Bean 유형 + * @param name Bean 이름 + * @param klass Bean 클래스 + * @return 지정한 이름과 클래스의 Bean + */ + public Optional getBean(String name, Class klass) { + if (!actx.containsBean(name)) + return Optional.empty(); + + return klass == null ? + Optional.of((T)actx.getBean(name)) : + Optional.of(actx.getBean(name, klass)); + } + private Log log() { return Log.get(getClass()); }