io.github.nichetoolkit.rest.util.ContextUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-toolkit-utils Show documentation
Show all versions of rest-toolkit-utils Show documentation
Rest toolkit utils project for Spring Boot
package io.github.nichetoolkit.rest.util;
import io.github.nichetoolkit.rest.holder.ContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import java.util.List;
/**
* ContextUtils
* @author Cyan ([email protected])
* @version v1.0.0
*/
@Slf4j
public class ContextUtils {
public static Object getBean(String name){
try {
return ContextHolder.getBean(name);
} catch (BeansException ex) {
log.warn("bean of name is {} no found, error: {}",name,ex.getMessage());
return null;
}
}
public static T getBean(Class clazz){
try {
return ContextHolder.getBean(clazz);
} catch (BeansException ex) {
log.warn("bean of type is {} no found, error: {}",clazz.getName(),ex.getMessage());
return null;
}
}
public static T getBean(String name, Class clazz){
try {
return ContextHolder.getBean(name, clazz);
} catch (BeansException ex) {
log.warn("bean of type is {} and name is {} no found, error: {}",clazz.getName(),name,ex.getMessage());
return null;
}
}
public static List getBeans(Class clazz){
try {
return ContextHolder.getBeans(clazz);
} catch (BeansException ex) {
log.warn("beans of type is {} no found, error: {}",clazz.getName(),ex.getMessage());
return null;
}
}
}