第四个参数老是报类型不匹配
来源:3-5 SpringBoot配置文件及自定义配置项
暗月zz
2020-07-17 00:37:08
package com.imooc.demo12.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class TestController {
@Value("${mall.config.name}")
private String name;
@Value("${mall.config.description}")
private String description;
@Value("${mall.config.hot-sales}")
private Integer hotSales;
@Value("mall.config.show-advert")
private Boolean showAdvert;
@RequestMapping("/out")
@ResponseBody
public String test() {
return "success";
}
@RequestMapping("/info")
@ResponseBody
public String info() {
return String.format("name:%s,description:%s,hot-sales:%s,show-advert:%s", name, description, hotSales, showAdvert);
}
}
错误信息是:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testController': Unsatisfied dependency expressed through field 'showAdvert'; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Boolean'; nested exception is java.lang.IllegalArgumentException: Invalid boolean value [mall.config.show-advert]
1回答
同学你好,同学是否有下图红框这个错误信息呢?如果有,显示的是什么呢?例如老师写的11true,这里显示的就是11true
2、老师猜测,同学是不是加载错配置文件了呢?
例如,老师这里指向的是prd这个文件,加载的就是这个文件中配置的
同学看看是不是看错文件了呢?
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
相似问题