2016-09-28 23 views
0

配置文件:ResourceBundleMessageSource會錯誤

@Configuration 
@ComponentScan("com.test.spring") 
public class SpringConfiguration { 

    @Bean("msg") 
    public MessageSource messageSource() { 
     ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); 
     messageSource.setBasename("classpath:locales/locales"); 
     messageSource.setDefaultEncoding("UTF-8"); 
     return messageSource; 
    } 
} 

文件locales.properties定位的src /主/資源/區域設置 但是,當我在XHTML撥打:

${msg.Welcome} 

並開始頁面,返回錯誤:

/index.xhtml: The class 'org.springframework.context.support.ResourceBundleMessageSource' does not have the property 'Welcome'. 

回答

0

嘗試檢索值並在jsp上顯示如下所示。

<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> 

<spring:message code="msg.Welcome"/> 

和你locales.properties文件應該有像下面

msg.Welcome= Welcome...!!! 

條目JSF只是html xmlns標籤去除taglib並嘗試像下面

<html xmlns:spring="http://www.springframework.org/tags"> 
<spring:message code="msg.Welcome"/> 
+0

Сan不能在使用jsf頁面指令taglib,只在一個jsp頁面上。 –

+0

嘗試一次以上更新評論 –

+0

這是行不通的。 –