如何将xml资源包添加到spring配置

时间:2016-02-29 21:18:48

标签: java xml spring

我正在尝试将 xml 资源包添加到spring xml文件中,并在代码中稍后获取它的值。 我收到错误:“在代码'node_list.severity.low'下找不到代码'ja_JP'的消息。”

资源包xml(List_ja_JP.xml):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>This is severity list</comment>
<entry key="node_list.severity">severity</entry>
<entry key="node_list.severity.low">Low</entry>
<entry key="node_list.severity.medium">Medium</entry>
<entry key="node_list.severity.high">High</entry>
<entry key="node_list.severity.urgent">Urgent</entry>
</properties>

配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<bean id="handleListResourceBundleBean"
      class="org.emiller.springcore.HandleListResourceBundle">
    <constructor-arg ref="readListBean"/>
</bean>

<bean id="listResourceBean"
      class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="org.emiller.springcore.List"/>
    <property name="defaultEncoding" value="UTF-8"/>
</bean>

<bean id="readListBean" class="org.emiller.springcore.ReadList"/> 
</beans>

试图获取列表项的代码:

public class ReadList implements IReadList {
@Override
public String getList() {
 ApplicationContext context = 
 new ClassPathXmlApplicationContext("org/emiller/springcore/config.xml");
 ResourceBundleMessageSource listObj=   
 (ResourceBundleMessageSource)context.getBean("listResourceBean");
 return listObj.getMessage("node_list.severity.low",null, Locale.JAPAN);
}
}

非常感谢

Eli Miller

0 个答案:

没有答案