gpt4 book ai didi

java - 找不到 MessageSource 的资源包

转载 作者:行者123 更新时间:2023-11-30 06:47:37 27 4
gpt4 key购买 nike

我想从属性文件中检索值,但 ApplicationContext 找不到该文件,我不知道为什么。查看我的代码和屏幕截图:

spring_part22.xml:

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

<bean id="point1" class="org.dxc.java.technology.part22.Point">
<property name="x" value="0"></property>
<property name="y" value="0"></property>
</bean>

<context:component-scan base-package="org.dxc.java.technology.part22" />
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>mymessage_en_US.properties</value>
</list>
</property>
</bean>
</beans>

mymessage.properties 的位置:

enter image description here

Drive.java

public class Drive {

static ApplicationContext context =
new ClassPathXmlApplicationContext("ConfigurationFiles/spring_part22.xml");

public static void main(String[] args) {
test1();
}

static void test1() {

System.out.println(context.getMessage("greeting", null, "Default Greeting", null));

}
}

当我运行 main 函数时,我得到以下输出:

Apr 15, 2017 11:42:39 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@497470ed: startup date [Sat Apr 15 11:42:39 CST 2017]; root of context hierarchy
Apr 15, 2017 11:42:39 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [ConfigurationFiles/spring_part22.xml]
Apr 15, 2017 11:42:40 AM org.springframework.context.support.ResourceBundleMessageSource getResourceBundle
WARNING: ResourceBundle [mymessage_en_US.properties] not found for MessageSource: Can't find bundle for base name mymessage_en_US.properties, locale en_US
Default Greeting

我不知道为什么 springframework 找不到该属性文件,任何人都可以帮助我或告诉我原因

最佳答案

而不是

<value>mymessage_en_US.properties</value>

用这个

<value>mymessage</value>

关于java - 找不到 MessageSource 的资源包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43421984/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com