自分のアプリケーションのBeanを作成しているconfigクラスがあります。私はアダプタビーンを作成している間にBeanプロパティを設定していますが、どういうわけかこれらのプロパティはクリアされ、コントローラクラスではnullに設定されています。 2時間のデバッグの後、私は空白を描いています。どのポインタもお願いします。私のAutowired Beanにnullのプロパティがあるのはなぜですか?
@RequiredArgsConstructor//lombok annotation to generate the constructor.
public class MyAdapter {//Trying to create a bean of this type
@NonNull private final MyPropertyObj prop;
@NonNull private final Integer timeout;
}
@Configuration
@Profile("!test")
class MyConfigClass{
@Bean
public MyAdapter adapter(){
MyPropertyObj prop= new MyPropertyObj();
return new MyAdapter(prop, 10);//Here I am setting prop and 10, but when I check auto wired adapter they are null.
}
}
public class MyController {
@Autowired private MyAdapter adapter;
//adapter gets injected, but adapter.prop and the adapter.timeout are null.
}
であなたのコントローラに注釈を付ける必要がありますが、あなたはhttp://stackoverflow.com/questions/19896870/why-is-my-spring-autowired-fieldを試してみました-null – Augustas
クラス 'myAdapter'のコンストラクタはどこですか? – Jens
@Augustas私はその質問を見ました。その質問は、手で新しいオブジェクトを作成し、その内部のプロパティが自動配線されることを期待することです。私がしようとしていることは違う。インスタンス化中に作成された私のBeanは、何らかの形で州を変更し、その属性をクリアします。 – learningtocode