Can't find bundle for base name elink, locale zh_CN /从配置文件获取值

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sftpFileAction' defined in URL [bundleresource://144.fwk618057235:1/com/gxll/moduels/fwfz/web/SftpFileActionController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.gxll.moduels.fwfz.web.SftpFileActionController]: Constructor threw exception; nested exception is java.util.MissingResourceException: Can't find bundle for base name elink, locale zh_CN


Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.gxll.moduels.fwfz.web.SftpFileActionController]: Constructor threw exception; nested exception is java.util.MissingResourceException: Can't find bundle for base name elink, locale zh_CN
 

Caused by: java.util.MissingResourceException: Can't find bundle for base name elink, locale zh_CN

原因:缺少名为elink的配置文件

解决:

迁移的原代码中有句ResourceBundle resourceBundle = ResourceBundle.getBundle("elink");是从配置文件中获取值

Can't find bundle for base name elink, locale zh_CN /从配置文件获取值_第1张图片

Can't find bundle for base name elink, locale zh_CN /从配置文件获取值_第2张图片

Can't find bundle for base name elink, locale zh_CN /从配置文件获取值_第3张图片Can't find bundle for base name elink, locale zh_CN /从配置文件获取值_第4张图片 

我换了种方法:

1.把配置文件elink.properties放在config下面 

2.在config的spring里面xx-spring.xml里面配置 :springutil获取springbean的工具,configuration读取配置文件 configeration里面配置了elink.properties的路径

Can't find bundle for base name elink, locale zh_CN /从配置文件获取值_第5张图片

Can't find bundle for base name elink, locale zh_CN /从配置文件获取值_第6张图片

 


		
			
				classpath:config/elink.properties
			
		
	
	

Configuration

public class Configuration extends PropertyPlaceholderConfigurer {

	private static final Logger log = LogManager.getLogger(Configuration.class);

	private Properties properties;
	private final static String ERR_MSG = "从配置文件中不能取得传入参数的返回值:";

	/**
	 * Use singleton pattern, only return one instance of Configuration.
	 * 
	 * @return Configuration
	 */
	public static Configuration getInstance() {
		return (Configuration) SpringUtil.getBean("configuration");
	}
	
	public String getValue(String key) {
		if (null == properties) {
			try {
				properties = mergeProperties();
			} catch (IOException e) {
				log.error(ERR_MSG + ":" + key);
				log.error(e);
			}
		}
		String value = properties.getProperty(key);
		if (value == null) {
			log.debug(ERR_MSG + ":" + key);
		}

		return value;
	}
	
}

 SpringUtil

public class SpringUtil implements ApplicationContextAware {
    private static ApplicationContext ctx;

    /**
     * just for Spring init web application context
     */
    public void setApplicationContext(ApplicationContext webApplicationContext)
        throws BeansException {
        ctx = webApplicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return ctx;
    }

    public static Object getBean(String name) {
        return getApplicationContext().getBean(name);
    }
    /**
     * 因为$符号出现在spring配置文件中,会被当作   符
     * 所以我们在spring配置文件中用:代替
     * @param src
     * @return
     */
    public static String unEscapeSpringXml(String src) {
		return src.replace(":{", "${");
	}
    /**
     * 因为$符号出现在spring配置文件中,会被当作   符
     * 所以我们在spring配置文件中用:代替
     * @param src
     * @return
     */
    public static String escapeSpringXml(String src) {
		return src.replace("${", ":{");
	}
    /**
     * 根据对象取到bean名
     * @param object
     * @return
     */
    public static String getBeanName(Object object){
    	if(object==null){
    		return null;
    	}
    	String[] beanNames = ctx.getBeanNamesForType(object.getClass());
    	for(String beanName : beanNames){
    		if(ctx.getBean(beanName).toString().equals(object.toString())){
    			return beanName;
    		}
    	}
    	return null;
    }
}

 

你可能感兴趣的:(Can't find bundle for base name elink, locale zh_CN /从配置文件获取值)