java - 使用spring的@Value注解出错
高洛峰
高洛峰 2017-04-17 17:43:48
0
4
593

容器启动的时候出错

配置文件如下:

报错信息如下:

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}"

怎么解决呢?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

모든 응답(4)
Ty80

1. 우선, 단일 테스트를 실행하는 경우 해당 속성의 위치가 올바른지 확인하는 것이 가장 좋습니다.

2. 구성 파일이 괜찮은 것으로 확인되면 Spring은 이를 처리하기 위한 도구 클래스 NumberUtils를 갖게 됩니다.

으아악

은 문자열을 Intger 유형으로 변환합니다. 그래도 작동하지 않으면 SPEL 문을 사용하여

을 강제로 변환해 볼 수 있습니다. 으아악
PHPzhong

'java.lang.String' 유형의 값을 필수 유형 'int'로 변환하지 못했습니다. 중첩 예외는 java.lang.NumberFormatException입니다. 입력 문자열의 경우: "${maxPic}"

이 오류는 너무나 명백합니다. . . init bean시 spring이 macPic 매개변수를 자동으로 변환하여 할당하는데 String에서 int로의 변환이 비정상적이다

左手右手慢动作

예외는 java.lang.NumberFormatException입니다. 입력 문자열: "${maxPic}"에 대해 따옴표를 사용하여 maxPic을 작성하고 오류를 보고하셨습니까?

迷茫

int 换成String
private String maxPic.

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿