弹簧条件特征启用

时间:2014-09-16 12:12:20

标签: java spring spring-annotations

对于这个问题,比方说,我们有一个MVC配置类:

@Configuration
public class MvcConfig extends WebMvcConfigurationSupport {

   @Bean
   public ViewResolver viewResolver() {
      return new InternalResourceViewResolver();
   }
   // bla-bla

}

我在配置类中通常有几个bean定义。问题是在启用某些功能(例如@EnableCaching@EnableMBeanExport@EnableAspectJAutoProxy时,如何控制这些功能的启用过程,即:

@Configuration
// @EnableCaching instead of this
public class MvcConfig extends WebMvcConfigurationSupport {

   @Autowired
   SomeResource someResource;

   @Bean
   public SomeBean someBean() {
      if(someResouce.someEvaluation(someParam)) {
         enableCaching();   // is that enabling possible?
      }
   }

   @Bean
   public ViewResolver viewResolver() {
      return new InternalResourceViewResolver();
   }
   // bla-bla

}

注意:我正在使用spring 3.2.x

0 个答案:

没有答案