对于这个问题,比方说,我们有一个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