使用IntelliJ IDEA开发工具解决方案:

总结原因,解决方案:

1,在使用messageSource.getMessage方法时,参数1的键名跟属性文件中键名不一致,比如Controller中是name ,而配置文件中却是names

2,因为使用springMvc提供了MessageSource类,所有也顺带给我们配置好了bean,我们只需注入(按名称注入)就行,但是要去总配置文件,也就是application,properties配置中添加

#为了spring找到资源文件
spring.messages.basename=message

使用Exlicps开发工具解决方案

总结原因:

1.如果你使用eclipse创建的工程是class和src分开的,那么资源属性文件一定要放在src目录以内。
2.属性文件名的写法:
messages_zh_CN.properties (中文)
messages_en_US.properties   (英文)
3.配置messageSource这个bean(注意:一定是messageSource不是messageResource ,这是Spring规定的)
 
一般报这个错,都是路径问题,所有改变bean的路径
默认配置是:

<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'.的解决方案的更多相关文章

  1. 解决org.springframework.context.NoSuchMessageException: No message found under code 'login.validate.er

    转自:https://blog.csdn.net/steveguoshao/article/details/36184971 在项目中遇到 org.springframework.context.No ...

  2. 关于Spring 国际化 No message found under code 的解决方案

    用spring做国际化时经常会报: org.springframework.context.NoSuchMessageException: No message found under code 'u ...

  3. SpringBoot 版本升级后报错 Cannot instantiate interface org.springframework.context.ApplicationContextInitializer

    本篇博客纯粹讲我遇到这个问题的解决以及思考,如果你想知道解决方法,可以直接看正确解决方案部分.因为是前端写的,所以可能有些明显的内容很容易就看出来了. 首先:升级后更新其他依赖,以及Applicati ...

  4. SpringCloud报错:Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

    今天启动用eureka的服务消费者时,一直出现问题. SpringCloud报错: Caused by: org.springframework.context.ApplicationContextE ...

  5. nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.报错解决

    近期在学springboot,学的时候遇到这个错,网上查了好多,改了不行,后来发现自己的配置类没有加@SpringBootApplication注解 Exception encountered dur ...

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

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

  8. 【转载】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 ...

  9. 【原创】大叔经验分享(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 ...

随机推荐

  1. K-均值聚类算法(K-means)

        K-means是一种无监督的学习,将相似的对象归到同一个簇中.可以将一批数据分为K个不同的簇,并且每个簇的中心采用簇中所含样本的均值计算而成.     K-means算法的K值需要由用户指定, ...

  2. PYTHON风格规范-Google 开源项目风格指南

    Python风格规范 分号 Tip 不要在行尾加分号, 也不要用分号将两条命令放在同一行. 行长度 Tip 每行不超过80个字符 例外: 长的导入模块语句 注释里的URL 不要使用反斜杠连接行. Py ...

  3. 用Zmq实现网关与游戏服全互连

    用Zmq实现网关与游戏服全互连(金庆的专栏)Zeromq无需bind, connect次序,可以在对方bind之前就connect, 可实现服务器以任意顺序启动.Zmq有自动重连功能,可实现服务器故障 ...

  4. 015-OC基础语法-OC笔记

    学习目标 1.[了解]Objective-C语言简介 2.[掌握]第一个OC程序 3.[掌握]OC中的字符串 4.[熟悉]OC中的一些玩意 5.[了解]面向过程与面向对象 6.[掌握]类的声明和实现 ...

  5. Swift基础之UITableView(之前写的知识点都是最新的2.2版本样式,欢迎大家参考,可以相互交流)

    //这里只是列举了经常使用的UITableView的属性和方法,其他的都可以类似使用,注意用法即可     //设置全局变量UITableView     var myTableView = UITa ...

  6. android 打造不同的Seekbar

    最近项目需要用到双向的seekbar,网上找了好多野不能达到要求,偶然一次机会看到了大众点评的例子,然后我最他做了优化,并对常用的seekbar做了总结. 向上两张图: 比如双向seekbar pub ...

  7. Kotlin For Android 示例代码实战

    下面就为大家介绍怎么使用Kotlin来开发Android 上面这篇中我们在下载Kotlin插件的时候也下了一个功能扩张插件,其实这个插件大有用处,它可以使得我们在不使用注解和第三方库的情况下不使用fi ...

  8. Java-ServletInputStream

    import java.io.InputStream; import java.io.IOException; /** * Provides an input stream for reading b ...

  9. Learning ROS for Robotics Programming Second Edition学习笔记(三) indigo rplidar rviz slam

    中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS for Robotics Pr ...

  10. WebApplicationContext初始化

    Spring 提供了用于启动WebApplicaionContext的Web容器监听器. 通过Web容器监听器引导: <!-- 1 指定配置文件 --> <context-param ...