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

com.hc360.rsf.config.RsfSpringLoader Maven / Gradle / Ivy

The newest version!
package com.hc360.rsf.config;

import java.io.IOException;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource;
import org.springframework.web.context.WebApplicationContext;

/**
 * 以静态变量保存Spring ApplicationContext, 可在任何代码任何地方任何时候中取出ApplicaitonContext.
 * 
 */
public class RsfSpringLoader implements ApplicationContextAware {
	private static Logger logger = LoggerFactory.getLogger(RsfSpringLoader.class);
	private static boolean init=false;

	private static ApplicationContext applicationContext;
	
	private static ConfigLoader configLoader=null;
	
	/**
	 * 业务系统需要取得 ConfigLoader
	 * @return
	 */
	public static ConfigLoader getConfigLoader(){
		return configLoader;
	}
	
	private Resource[] rsfConfigLocations;
	/**
	 * 注入rsf配置文件路径 
	 * @param rsfConfigLocations
	 */
	
	public void setRsfConfigLocations(final Resource[] paths) {
		if(paths==null){
			return ;
		}
		rsfConfigLocations=new Resource[paths.length];
		System.arraycopy(paths, 0, rsfConfigLocations, 0, paths.length);
	}
	
	/**
	 * 启动RSF
	 */
	private void start(){
		try{
			if(rsfConfigLocations==null || rsfConfigLocations.length==0){
				logger.info("RsfSpringLoader 无配置文件,不执行启动");
				return ;
			}
			init=true;	
			logger.info("RsfSpringLoader 启动");
			int len = rsfConfigLocations.length;
			String[] confs = new String[len];
			for(int i=0;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy