当配置文件有某个配置项,才启用对应配置 @ConditionalOnProperty

阅读更多
当存在配置:xxx.security.social.qq.app-id 时,才启用该配置
@ConditionalOnProperty(prefix = "xxx.security.social.qq", name = "app-id")
public class QQAutoConfig extends SocialAutoConfigurerAdapter {

	@Autowired
	private SecurityProperties securityProperties;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter
	 * #createConnectionFactory()
	 */
	@Override
	protected ConnectionFactory createConnectionFactory() {
		QQProperties qqConfig = securityProperties.getSocial().getQq();
		return new QQConnectionFactory(qqConfig.getProviderId(), qqConfig.getAppId(), qqConfig.getAppSecret());
	}

}

你可能感兴趣的:(当配置文件有某个配置项,才启用对应配置 @ConditionalOnProperty)