プロパティで@Value
を使用したいと思いますが、私はいつも0
(int)を取得します。
しかし、コンストラクタパラメータでは動作します。春@Autowiredと@Valueプロパティが機能しません
例:
@Component
public class FtpServer {
@Value("${ftp.port}")
private int port;
public FtpServer(@Value("${ftp.port}") int port)
{
System.out.println(port); // 21, loaded from the application.properties.
System.out.println(this.port); // 0???
}
}
オブジェクトはコンストラクタのパラメータが動作しない他、春管理されています。
この奇妙な動作の原因を知っている人はいますか?
コンストラクタとクラス名が一致しません。私は入力ミスです。 –
Springは、存在しないオブジェクトにも値を設定できます...オブジェクトは、コンストラクタの実行後に存在します。 –