我正在尝试使用 @Configuration bean 而不是 XML 来实现 Togglz & Spring。我不确定如何配置 Configuration bean 的返回类型。例如:
@Configuration
public class SystemClockConfig {
@Bean
public SystemClock plainSystemClock() {
return new PlainSystemClock();
}
@Bean
public SystemClock awesomeSystemClock() {
return new AwesomeSystemClock();
}
@Bean
public FeatureProxyFactoryBean systemClock() {
FeatureProxyFactoryBean proxyFactoryBean = new FeatureProxyFactoryBean();
proxyFactoryBean.setActive(awesomeSystemClock());
proxyFactoryBean.setInactive(plainSystemClock());
proxyFactoryBean.setFeature(Features.AWESOME_SYSTEM_CLOCK.name());
proxyFactoryBean.setProxyType(SystemClock.class);
return proxyFactoryBean;
}
}
该systemClock
方法返回 aFeatureProxyFactoryBean
但此 bean 的客户端需要 a SystemClock
。当然,编译器对此感到非常震惊。
我想它只在使用 XML 配置时才有效。使用配置 bean 时我应该如何处理它?