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

容器启动的时候出错

配置文件如下:

报错信息如下:

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 ステートメントを使用して

を強制的に変換してみてください。 リーリー
いいねを押す +0
PHPzhong

型 'java.lang.String' の値を必要な型 'int' に変換できませんでした。ネストされた例外は java.lang.NumberFormatException です: 入力文字列: "${maxPic}"

この間違いは明らかです。 。 。 init Bean 時に Spring は macPic パラメータを自動的に変換して割り当てますが、String から int への変換が異常です

いいねを押す +0
左手右手慢动作

例外は java.lang.NumberFormatException です: 入力文字列: "${maxPic}" について、引用符付きで maxPic を記述し、エラーを報告しましたか?

いいねを押す +0
迷茫

int 换成String
private String maxPic.

いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート