У меня есть имя проекта Spring: SpringExample
Структура каталогов:
locale.xml для весны:
<bean id="customerService" class="com.mkyong.customer.services.CustomerService" />
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<value>\SpringExample\conf\messages</value>
</property>
</bean>
код для CustomerService:
package com.mkyong.customer.services;
public class CustomerService implements MessageSourceAware
{
private MessageSource messageSource;
public void setMessageSource(MessageSource messageSource) {
this.messageSource = messageSource;
}
public void printMessage(){
String name = messageSource.getMessage("customer.name",
new Object[] { 28, "http://www.mkyong.com" }, Locale.US);
System.out.println("Customer name (English) : " + name);
}
код для класса приложения (основной класс):
package com.mkyong.common;
import java.util.Locale;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.mkyong.customer.services.CustomerService;
public class App {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { "locale.xml" });
// get the message resource inside context
String name = context.getMessage("customer.name", new Object[] { 28,
"http://www.mkyong.com" }, Locale.US);
System.out.println("Customer name (English) : " + name);
// get the message resource inside the bean
CustomerService cust = (CustomerService) context
.getBean("customerService");
cust.printMessage();
}
}
Но он не может связать файл proprtie, потому что его нет в пакете.
я получаю исключение:
ВНИМАНИЕ: ResourceBundle [\ SpringExample \ conf? \ Messages] не найден для
Источник сообщения: не удается найти пакет для базового имени
\ SpringExample \ conf? \ Messages, locale ru_US
как я могу получить его в комплекте с ресурсом внешней папки, как в моем примере?