検索

ホームページ  >  に質問  >  本文

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日前599

全員に返信(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
  • キャンセル返事