关于国际化时报org.springframework.context.NoSuchMessageException错,具体到No message found under code '你的键名' for locale 'zh_CN'.的解决方案
使用IntelliJ IDEA开发工具解决方案:
总结原因,解决方案:
1,在使用messageSource.getMessage方法时,参数1的键名跟属性文件中键名不一致,比如Controller中是name ,而配置文件中却是names
2,因为使用springMvc提供了MessageSource类,所有也顺带给我们配置好了bean,我们只需注入(按名称注入)就行,但是要去总配置文件,也就是application,properties配置中添加
#为了spring找到资源文件
spring.messages.basename=message
使用Exlicps开发工具解决方案
总结原因:
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<!--默认到当前web应用下找 -->
<value>classpath*:messages</value>
<value>classpath:org/hibernate/validator/ValidationMessages</value>
</list>
</property>
<property name="useCodeAsDefaultMessage" value="false"/>
<property name="defaultEncoding" value="UTF-8"/>
<property name="cacheSeconds" value="60"/>
</bean>
改变路径位置:比如你的属性文件放在resources/message/messages.propeties,那么就改变路径为:
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<!-- 默认到当前web应用下找 -->
<value>classpath:/messages/messages</value>
<value>classpath:/messages/ValidationMessages</value>
</list>
</property>
<property name="useCodeAsDefaultMessage" value="false"/>
<property name="defaultEncoding" value="UTF-8"/>
<property name="cacheSeconds" value="60"/>
</bean>
问题解决方案纯粹个人方式,若有不足,请评论区提出,谢谢
关于国际化时报org.springframework.context.NoSuchMessageException错,具体到No message found under code '你的键名' for locale 'zh_CN'.的解决方案的更多相关文章
- 解决org.springframework.context.NoSuchMessageException: No message found under code 'login.validate.er
转自:https://blog.csdn.net/steveguoshao/article/details/36184971 在项目中遇到 org.springframework.context.No ...
- 关于Spring 国际化 No message found under code 的解决方案
用spring做国际化时经常会报: org.springframework.context.NoSuchMessageException: No message found under code 'u ...
- SpringBoot 版本升级后报错 Cannot instantiate interface org.springframework.context.ApplicationContextInitializer
本篇博客纯粹讲我遇到这个问题的解决以及思考,如果你想知道解决方法,可以直接看正确解决方案部分.因为是前端写的,所以可能有些明显的内容很容易就看出来了. 首先:升级后更新其他依赖,以及Applicati ...
- SpringCloud报错:Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
今天启动用eureka的服务消费者时,一直出现问题. SpringCloud报错: Caused by: org.springframework.context.ApplicationContextE ...
- nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.报错解决
近期在学springboot,学的时候遇到这个错,网上查了好多,改了不行,后来发现自己的配置类没有加@SpringBootApplication注解 Exception encountered dur ...
- springboot 启动报错"No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available"
1.问题 springboot启动报错 "D:\Program Files\Java\jdk-11\bin\java.exe" -XX:TieredStopAtLevel=1 -n ...
- IDEA启动tomcat报错:java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext、ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component
先看错误日志: -May- ::.M26 -May- :: :: UTC -May- ::29.845 信息 [main] org.apache.catalina.startup.VersionLog ...
- 【转载】springboot启动报错(Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWe)
SpringBoot启动时的异常信息如下: 1 "C:\Program Files\Java\jdk1.8.0_161\bin\java" ......... com.fangxi ...
- 【原创】大叔经验分享(16)Context namespace element 'component-scan' and its parser class [org.springframework.context.annotation.ComponentScanBeanDefinitionParser] are only available on JDK 1.5 and higher
今天尝试运行一个古老的工程,配置好之后编译通过,结果运行时报错: org.springframework.beans.factory.BeanDefinitionStoreException: Une ...
随机推荐
- Chapter 2 User Authentication, Authorization, and Security(6):服务器权限授予粒度
原文出处:http://blog.csdn.net/dba_huangzj/article/details/38867489,专题目录:http://blog.csdn.net/dba_huangzj ...
- Spring AOP 初探
本文可作为北京尚学堂spring课程的学习笔记 首先谈谈什么是AOP 它能干什么 AOP Aspect Oriented Programming(面向切面的编程) 什么叫面向切面? 就是我们可以动态的 ...
- 四大组件之 BroadcastReceiver小结
总结提高,与君共勉 1. BroadcastReceiver是什么? BroadcastReceiver也就是"广播接收者"的意思,顾名思义,它就是用来接收来自系统和应用中的广播. ...
- 小知识点BeanUtils.copyProperties
通过BeanUtils.copyProperties可以时间拷贝对象中的值,下面的new String[]{"cid","agreeFlag"," ...
- XBMC源代码分析 4:视频播放器(dvdplayer)-解码器(以ffmpeg为例)
XBMC分析系列文章: XBMC源代码分析 1:整体结构以及编译方法 XBMC源代码分析 2:Addons(皮肤Skin) XBMC源代码分析 3:核心部分(core)-综述 本文我们分析XBMC中视 ...
- C++对象模型(四):class成员初始化列表(Member Initialization List)
本文是Inside C++ Object Model Chapter 2 部分的读书笔记. 编译器如何处理初始化成员列表的. 下列情况中,必须要使用member initialization list ...
- javascript语法之String对象
学习String类就是学习它的一些方法,主要用到方法全部罗列出来.如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transition ...
- Android 使用com.j256.ormlite
在web开发中经常采用的hibernate,在android也提供了一个ormlite 导入所需jar包后 /** * SQLiteHelperOrm.java * 版权所有(C) 2014 * 创建 ...
- 《java入门第一季》之面向对象(修饰符的概念和总结)
还是由于eclipde等ide的强大功能,会自动提示你修饰符是否可行.所以对修饰符的作用了解即可: 修饰符: 权限修饰符:private,默认的,protected,public ...
- JavaScript进阶(三)常见工具(校验、通用)
JS常见工具(校验.通用) // 姓名校验 var checkName = function(name) { // 收货人姓名校验(准则:姓名为2-4汉字) var regu = /^[\u4E00- ...