All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.javaclub.sword.util.SpringIoCompatible Maven / Gradle / Ivy

The newest version!
/*
 * @(#)SpringIoCompatible.java	2022-5-24
 *
 * Copyright (c) 2022. All Rights Reserved.
 *
 */

package com.github.javaclub.sword.util;

import java.util.Map;

import com.github.javaclub.sword.component.SpringContextUtil;
import com.github.javaclub.toolbox.spring.BeanFactory;
import com.google.common.collect.Maps;

/**
 * SpringIoCompatible
 *
 * @author Gerald Chen
 * @version $Id: SpringIoCompatible.java 2022-5-24 9:57:44 Exp $
 */
public final class SpringIoCompatible {
	
	public static  Map getBeansOfType(Class clazz) {
		
		try {
			Map map = BeanFactory.getInstance().getBeansOfType(clazz);
			if (null != map) {
				return map;
			}
			return SpringContextUtil.getBeansOfType(clazz);
		} catch (Throwable e) {
		}
		return Maps.newHashMap();
		
	}

	public static  T getBean(Class clazz) {
		try {
			T object = BeanFactory.getInstance().getBean(clazz);
			if (null != object) {
				return object;
			}
			return SpringContextUtil.getBean(clazz);
		} catch (Throwable e) {
		}
		return null;
	}
	
	public static  T getBean(String beanName) {
		try {
			T object = (T) BeanFactory.getInstance().getBean(beanName);
			if (null != object) {
				return object;
			}
			return SpringContextUtil.getBean(beanName);
		} catch (Exception e) {
		}
		return null;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy