English 中文(简体)
为什么我不能使用<spring:message的标签?
原标题:Why I can t use tag of <spring:message?

Using in my jsp like:
<spring:message code="key1"/> , I got error: ** Root cause is: No message found under code key1 for locale zh_CN . javax.servlet.jsp.JspTagException: No message found under code key1 for locale zh_CN . at org.springframework.web.servlet.tags.MessageTag.doStartTagInternal(MessageTag.java:184) at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79) at

下面是我的代码:

<bean id="messageSource"        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="com.bk.message.Message" />
        <property name="defaultEncoding" value="UTF-8" />
        <property name="useCodeAsDefaultMessage" value="false" />
    </bean>

这是我的财产:

Message_zh_CN.properties under folder src/com/bk/message  
key1=This
最佳回答

嘿,basename应该是一个路径,而不是包名。请参阅文档此处和一些讨论此处

顺便说一句,如果你想调试,只需在代码中的某个地方注入bean。

问题回答

嘿,把配置放在applicationContext.xml中更有用。然后你可以从类路径加载属性,比如

 <bean id="messageSource"
   class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basenames">
            <list>
            <value>i18n/views</value>
                   </list>      
            </property>     
    </bean>

现在,您可以加载许多自己定义的属性。





相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签