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

com.ajaxjs.spring.DiContextUtil Maven / Gradle / Ivy

Go to download

AJAXJS aims to full-stack, not only the server-side framework, but also integrates the front-end library. It'€™s written in HTML5 + Java, a successor to the JVM platform, efficient, secure, stable, cross-platform and many other advantages, but it abandoned the traditional enterprise architecture brought about by the large and bloated, emphasizing the lightweight, and fast, very suitable for the Internet fast application.

The newest version!
package com.ajaxjs.spring;

import java.util.Locale;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 方便静态方法、JSP 调用注入的组件
 */
@Component
public class DiContextUtil implements ApplicationContextAware {
	private static ApplicationContext context;

	@Override
	public void setApplicationContext(ApplicationContext contex) throws BeansException {
		context = contex;
	}

	/**
	 * 获取上下文
	 * 
	 * @return 上下文对象
	 */
	public static ApplicationContext getApplicationContext() {
		return context;
	}

	/**
	 * 获取已注入的对象
	 * 
	 * @param  对象类型
	 * @param clz 对象类型引用
	 * @return 组件对象
	 */
	public static  T getBean(Class clz) {
		return context.getBean(clz);
	}

	/**
	 * 获取已注入的对象
	 * 
	 * @param beanName 组件对象 id
	 * @return 组件对象
	 */
	public static Object getBean(String beanName) {
		return context.getBean(beanName);
	}

	/**
	 * 
	 * @param key
	 * @return
	 */
	public static String getMessage(String key) {
		return context.getMessage(key, null, Locale.getDefault());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy