容器启动的时候出错
配置文件如下:
报错信息如下:
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.