java – Spring消息中的StackoverflowExcepton i18n ReloadableResourceBundleMessageSource
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – Spring消息中的StackoverflowExcepton i18n ReloadableResourceBundleMessageSource,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2237字,纯文字阅读大概需要4分钟。
内容图文
![java – Spring消息中的StackoverflowExcepton i18n ReloadableResourceBundleMessageSource](/upload/InfoBanner/zyjiaocheng/789/90411c7f46f9465db9e2b36344df006b.jpg)
我在我的Spring网络应用程序中启用消息i18n.为此,我在servlet.xml中有下面的代码
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages/message"/>
<property name="defaultEncoding" value="UTF-8"/>
</bean>
添加上面的代码后,只要我在浏览器中点击我的应用程序,就会出现以下异常日志:
SEVERE: Servlet.service() for servlet [default] in context with path [/ERP-Web] threw exception [Filter execution threw an exception] with root cause
java.lang.StackOverflowError
at org.springframework.context.support.ReloadableResourceBundleMessageSource.getMergedProperties(ReloadableResourceBundleMessageSource.java:235)
at org.springframework.context.support.ReloadableResourceBundleMessageSource.resolveCodeWithoutArguments(ReloadableResourceBundleMessageSource.java:176)
at org.springframework.context.support.AbstractMessageSource.getMessageInternal(AbstractMessageSource.java:209)
at org.springframework.context.support.AbstractMessageSource.getMessageFromParent(AbstractMessageSource.java:257)
最后2行重复了100次,并给我StackoverflowException.
当我使用ResourceBundleMessageSource类时,会发生完全相同的异常.
我的春季版是4.3.6.RELEASE.
以下是我的属性文件的内容
action.add.success = New {0} added successfully.
action.add.failure = Some error occurred in adding new {0}. Please try again later or contact administrator.
示例项目是GitHub
解决方法:
非常奇怪的情况;-)
基本问题是messageSource自动连接到自身(在parentMessageSource属性中),因为你使用default-autowire =“byType”这会导致未知消息代码的stackoverflow异常混乱一切.必须说logback会给乱七八糟的东西带来麻烦,因为有时似乎异常发生在代码中,Log4J会更好地处理它.
Autowiring is not good for big projects,这个你的情况是一个经典案例,但是如果你必须使用它改变messageSource bean添加以下内容:
<property name="parentMessageSource"><null/></property>
通过这种方式,您可以自己连接父级,并且不会发生自动装配.
这将恢复正常情况,其中未使用NoSuchMessageException报告未找到的消息
然后:
>在控制器中,您必须请求hello.world消息,而不是消息
>您缺少默认资源,即无语言环境后缀文件,表示默认语言环境或您的应用程序.在您的情况下,将是messages / message.properties为简单起见,应用程序的默认语言环境是您拥有所有消息的语言环境.从那开始,然后添加新语言(可能不完整).
内容总结
以上是互联网集市为您收集整理的java – Spring消息中的StackoverflowExcepton i18n ReloadableResourceBundleMessageSource全部内容,希望文章能够帮你解决java – Spring消息中的StackoverflowExcepton i18n ReloadableResourceBundleMessageSource所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。