我想使用Sping Boot @Conditional和Mapstruct。我想使用属性文件限制Spring Bean的创建。我使用@Conditional进行相同的操作。如何为mapstruct bean实现它?
9rygscc11#
您可以使用条件bean创建Configuration类:
@Configuration class ConditionalBeanConfiguration { @Bean @Conditional... <-- ConditionalBean conditionalBean(){ return new ConditionalBean(); }; }
字符串所以它可能看起来像:
@Configuration class MapperBeanConfiguration { @Bean @ConditionalOnProperty(name = "my.property.enabled", havingValue = "true") public MyMapper myMapperImplV1() { return new MyMapperImplV1(); } @Bean @ConditionalOnProperty(name = "my.property.enabled", havingValue = "false", matchIfMissing = true) public MyMapper myMapperImplV2() { return new MyMapperImplV2(); } }
型你可以在这篇文章中了解更多:working with springs conditional annotation for conditional bean registration
1条答案
按热度按时间9rygscc11#
您可以使用条件bean创建Configuration类:
字符串
所以它可能看起来像:
型
你可以在这篇文章中了解更多:working with springs conditional annotation for conditional bean registration