容器启动的时候出错
配置文件如下:
报错信息如下:
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. 우선, 단일 테스트를 실행하는 경우 해당 속성의 위치가 올바른지 확인하는 것이 가장 좋습니다.
2. 구성 파일이 괜찮은 것으로 확인되면 Spring은 이를 처리하기 위한 도구 클래스
으아악NumberUtils
를 갖게 됩니다.은 문자열을 Intger 유형으로 변환합니다. 그래도 작동하지 않으면
을 강제로 변환해 볼 수 있습니다. 으아악SPEL
문을 사용하여'java.lang.String' 유형의 값을 필수 유형 'int'로 변환하지 못했습니다. 중첩 예외는 java.lang.NumberFormatException입니다. 입력 문자열의 경우: "${maxPic}"
이 오류는 너무나 명백합니다. . . init bean시 spring이 macPic 매개변수를 자동으로 변환하여 할당하는데 String에서 int로의 변환이 비정상적이다
예외는 java.lang.NumberFormatException입니다. 입력 문자열: "${maxPic}"에 대해 따옴표를 사용하여 maxPic을 작성하고 오류를 보고하셨습니까?
int 换成String
private String maxPic.