5

私のxml構成ファイルに書くことができます

 <context:component-scan base-package="com.my.stuff"/>

次に、Java ベースの構成に進みます。@Configurationそこになくても、ベースクラスでそれを行うにはどうすればよいApplicationContextですか?

4

2 に答える 2

15

@ComponentScanアノテーションを構成クラスに使用できます。

例 :

@Configuration
@ComponentScan("com.acme.app.services")
 public class AppConfig {
     @Bean
     public MyBean myBean() {
         // instantiate, configure and return bean ...
     }
 }
于 2012-10-10T11:54:44.600 に答える
3

spring < 3.1 の場合、 @Configuration クラスの @PostConstruct メソッドでhttp://static.springsource.org/spring/docs/2.5.x/api/org/springframework/context/annotation/ClassPathBeanDefinitionScanner.htmlを使用できます。もちろん、ApplicationContext を @Configuration に自動配線する必要があります。

于 2012-10-10T12:03:04.207 に答える