3

Spring 3では、@ PostConstructを有効にするために、定義する<context:annotation-config>必要がありますか?<context:component-scan>

applicationContext.xml

<context:component-scan base-package="net.test" />

........
...

<context:annotation-config />

ManagedBeanにgetLazyLoadメソッドがあり、このBeanに@PostConstructを使用したいと思います。

ありがとう

4

2 に答える 2

3

<context:annotation-config>十分です。その後、context.xmlからBeanをインスタンス化でき、@ PostConstruct、@ Autowired、@ Resource、およびSpringがサポートするその他のアノテーションが処理されます。component-scan Annotation-configモードを使用する場合は、デフォルトで有効になっていることに注意してください。

于 2012-12-19T11:51:37.840 に答える
2

あなたのBeanには、クラスレベルで関連するアノテーションがありません@Component

<context:component-scan base-package="net.test" />

必須ではありません。

で作業する@PostConstructだけ<context:annotation-config />で十分です。

編集1:

Beanに以下のアノテーションがある場合

@Component, @Repository, @Service, or @Controller.

次に<context:component-scan />、指定されたパッケージでそれらのBeanをスキャンします。

于 2012-12-19T11:51:47.490 に答える