解决org.springframework.context.NoSuchMessageException: No message found under code 'exportexcel.logis

本文记录了解决Spring框架中出现的NoSuchMessageException异常的过程,该异常提示无法找到指定代码对应的国际化消息。通过调整配置文件的加载路径,最终解决了问题。

在项目中遇到
org.springframework.context.NoSuchMessageException: No message found under code ‘exportexcel.logisticsCompany’ for locale ‘zh_CN’.
搞了半天也没解决,检查exportexcel.logisticsCompany是否写对了,查了半天一直是对的,感觉就是路径问题了。

刚开始的spring配置:

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <!-- 在web环境中一定要定位到classpath 否则默认到当前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>

因为我是把配置文件单独放在config文件夹里面的,跟代码目录是同级的一个目录,就以为classpath*:messages要加星号,后来发现去掉就对了

package com.zzyl.plan.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; import com.zzyl.nursing.dto.NursingPlanDto; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.zzyl.common.annotation.Log; import com.zzyl.common.core.controller.BaseController; import com.zzyl.common.core.domain.AjaxResult; import com.zzyl.common.enums.BusinessType; import com.zzyl.plan.domain.NursingPlan; import com.zzyl.plan.service.INursingPlanService; import com.zzyl.common.utils.poi.ExcelUtil; import com.zzyl.common.core.page.TableDataInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; /** * 护理计划Controller * * @author ruoyi * @date 2025-08-07 */ @Api(tags = "护理计划管理") @RestController @RequestMapping("/nursing/plan") public class NursingPlanController extends BaseController { @Autowired private INursingPlanService nursingPlanService; /** * 查询护理计划列表 */ @ApiOperation("查询护理计划列表") @PreAuthorize("@ss.hasPermi('nursing:plan:list')") @GetMapping("/list") public TableDataInfo list( @ApiParam("护理计划查询参数") NursingPlan nursingPlan) { startPage(); List<NursingPlan> list = nursingPlanService.selectNursingPlanList(nursingPlan); return getDataTable(list); } /** * 导出护理计划列表 */ @ApiOperation("导出护理计划列表") @PreAuthorize("@ss.hasPermi('nursing:plan:export')") @Log(title = "护理计划", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export( @ApiParam("HTTP响应对象") HttpServletResponse response, @ApiParam("护理计划查询参数") NursingPlan nursingPlan) { List<NursingPlan> list = nursingPlanService.selectNursingPlanList(nursingPlan); ExcelUtil<NursingPlan> util = new ExcelUtil<NursingPlan>(NursingPlan.class); util.exportExcel(response, list, "护理计划数据"); } /** * 获取护理计划详细信息 */ @ApiOperation("获取护理计划详细信息") @PreAuthorize("@ss.hasPermi('nursing:plan:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo( @ApiParam("护理计划ID") @PathVariable("id") Long id) { return success(nursingPlanService.selectNursingPlanById(id)); } /** * 新增护理计划 */ @ApiOperation("新增护理计划") @PreAuthorize("@ss.hasPermi('nursing:plan:add')") @Log(title = "护理计划", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add( @ApiParam("护理计划对象") @RequestBody NursingPlanDto dto) { return toAjax(nursingPlanService.insertNursingPlan(dto)); } /** * 修改护理计划 */ @ApiOperation("修改护理计划") @PreAuthorize("@ss.hasPermi('nursing:plan:edit')") @Log(title = "护理计划", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit( @ApiParam("护理计划对象") @RequestBody NursingPlan nursingPlan) { return toAjax(nursingPlanService.updateNursingPlan(nursingPlan)); } /** * 删除护理计划 */ @ApiOperation("删除护理计划") @PreAuthorize("@ss.hasPermi('nursing:plan:remove')") @Log(title = "护理计划", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove( @ApiParam("护理计划ID数组") @PathVariable Long[] ids) { return toAjax(nursingPlanService.deleteNursingPlanByIds(ids)); } } @Data @ApiModel(description = "护理计划") public class NursingPlanVo { /** * 护理计划id */ private Long id; /** * 排序号 */ @ApiModelProperty(value = "护理计划排序号") private Integer sortNo; @ApiModelProperty(value = "护理计划名称") private String planName; @ApiModelProperty(value = "状态(0:禁用,1:启用)") private Integer status; @ApiModelProperty(value = "护理计划项目计划列表") List<NursingProjectPlanVo> projectPlans; } 这是我相应给前端的实体,如何修改
最新发布
08-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值