찾다

 >  Q&A  >  본문

java - 使用spring的@Value注解出错

容器启动的时候出错

配置文件如下:

报错信息如下:

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

怎么解决呢?

高洛峰高洛峰2887일 전605

모든 응답(4)나는 대답할 것이다

  • PHP中文网

    PHP中文网2017-04-17 17:45:48

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

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

    으아악

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

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

    회신하다
    0
  • PHPz

    PHPz2017-04-17 17:45:48

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

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

    회신하다
    0
  • ringa_lee

    ringa_lee2017-04-17 17:45:48

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

    회신하다
    0
  • 迷茫

    迷茫2017-04-17 17:45:48

    int 换成String
    private String maxPic.

    회신하다
    0
  • 취소회신하다