使用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. Windows Server2012R2 安装 SharePoint 2013 的必备组件

    Windows Server2012R2目前支持SharePoint Server 2013 with Service Pack 1 和 SharePoint Foundation 2013 with ...

  2. nginx 详解反向代理负载均衡

    什么是反向代理负载均衡 使用代理服务器可以将请求转发给内部的Web服务器,使用这种加速模式显然可以提升静态网页的访问速度.因此也可以考虑使用这种技术,让代理服务器将请求 均匀转发给多台内部Web服务器 ...

  3. gcov 统计 inline 函数

    gcov 统计 inline 函数 (金庆的专栏) gcov可以统计 inline  函数,可是实际使用中碰到统计次数总是为0的现象. 假设类A的头文件为 A.h, 实现文件为 A.cpp. A 有几 ...

  4. 谈谈Ext JS的组件——布局的使用方法续二

    绝对布局(Ext.layout.container.Absolute) 绝对布局让我回想到了使用Foxpro开发的时候,哪时候的界面布局就是这样,通过设置控件的左上角坐标(x,y)和宽度来进行的,因为 ...

  5. Linux进程实践(1) --Linux进程编程概述

    进程 VS. 程序 什么是程序? 程序是完成特定任务的一系列指令集合. 什么是进程? [1]从用户的角度来看:进程是程序的一次执行过程 [2]从操作系统的核心来看:进程是操作系统分配的内存.CPU时间 ...

  6. 预装WIN8的电脑是GPT分区模式,无法安装WIN7

    本人的笔记本自带的是WIN8系统,现在想安装WIN7的系统,但是安装不了,提示"windows无法安装到这个磁盘.选中的磁盘采用GPT分区形式". 通过上网搜索得知WIN7一般安装 ...

  7. 《android入门第一季》之android目录结构详解

    在搭建Android开发环境及简单地建立一个HelloWorld项目后,本篇将通过HelloWorld项目来介绍Android项目的目录结构.本文的主要主题如下: 1.HelloWorld项目的目录结 ...

  8. 《java入门第一季》之java语法部分小案例

    到这里举一个小例子把语法部分梳理一下,下一节开始进入java正式基础--面向对象的学习整理. 案例: /* 某个公司采用公用电话传递数据信息,数据是小于8位的整数,为了确保安全, 在传递过程中需要加密 ...

  9. 安装nodejs中遇到的问题

    make clean 出现时间不对的问题的时候,主要是系统时间设置错误. 用date -s 来分别设置日期和时间 用clock -w来写入CMS 安装g++ yum -y install gcc-c+ ...

  10. AngularJS进阶(十一)AngularJS实现表格数据的编辑,更新和删除

    AngularJS实现表格数据的编辑,更新和删除 效果 实现 首先,我们先建立一些数据,当然你可以从你任何地方读出你的数据 var app = angular.module('plunker', [' ...