광고
광고
반응형
# 방법
ApplicationContext.containsBean(String beanName);
# 예제
package com.test.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
@Component
public class SearchUtil {
@Autowired
ApplicationContext applicationContext;
public boolean checkService(String serviceName) {
if (applicationContext.containsBeanDefinition(serviceName)) {
return true;
} else {
return false;
}
}
}
# 참고: 현재 ApplicationContext에 등록된 Bean 전체 조회 방법
ApplicationContext.getBeanDefinitionNames();
반응형