Tom
Tom

Reputation: 2847

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

And the following is my code:

<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>

here is my properties:

Message_zh_CN.properties under folder src/com/bk/message  
key1=This

Upvotes: 1

Views: 5462

Answers (2)

liuyang
liuyang

Reputation: 11

Hey,it is more useful to put the configuration in applicationContext.xml. And then you can load the properties from classpath,such as

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

Now, you can load many properties which are defined by youself.

Upvotes: 1

dfichter
dfichter

Reputation: 1078

Hey, basename should be a path, not a package name. See the documentation here and some discussion here.

If you want to debug, btw, just inject the bean somewhere in your code.

Upvotes: 2

Related Questions