2016-09-21 9 views
-1

自分のアプリケーションの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. 
} 
+0

であなたのコントローラに注釈を付ける必要がありますが、あなたはhttp://stackoverflow.com/questions/19896870/why-is-my-spring-autowired-fieldを試してみました-null – Augustas

+0

クラス 'myAdapter'のコンストラクタはどこですか? – Jens

+0

@Augustas私はその質問を見ました。その質問は、手で新しいオブジェクトを作成し、その内部のプロパティが自動配線されることを期待することです。私がしようとしていることは違う。インスタンス化中に作成された私のBeanは、何らかの形で州を変更し、その属性をクリアします。 – learningtocode

答えて

0

あなたは

@Controller 

注釈

+0

こんにちはJana、ありがとう、私のコントローラは、私がアダプタビーンと一緒に作成するBeanです。私はコントローラの他のプロパティがokに設定されていることがわかります。 – learningtocode

+0

おそらく、それは@Profile( "!test")と関係があり、注釈なしで試してみましたか? – Janar

関連する問題