容器启动的时候出错
配置文件如下:
报错信息如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'communityController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private int cn.wanjubang.toy.core.controller.Basecontroller.maxPic; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException: For input string: "${maxPic}"
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private int cn.wanjubang.toy.core.controller.Basecontroller.maxPic; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException: For input string: "${maxPic}"
怎么解决呢?
1. First of all, make sure that the location of your properties is correct. If you are running a single test, it is best to make sure that it is also in the test path.
2. If the configuration file is confirmed to be OK, spring will have a tool class
NumberUtils
to handle it.NumberUtils
来处理。会把string转换成Intger类型,如果还是不行的话,可以试试用
It will convert the string into Intger type. If it still doesn’t work, you can try to use theSPEL
SPEL
statement to force the conversion🎜 rrreeeFailed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException: For input string: "${maxPic}"
This error is so obvious. . . When init bean, spring automatically converts and assigns macPic parameters, but the conversion from String to int is abnormal
exception is java.lang.NumberFormatException: For input string: "${maxPic}", did you write maxPic with quotation marks and reported an error
int replaced by String
private String maxPic.