org.springframework.boot.autoconfigure.condition.ConditionalOnProperty Java Examples
The following examples show how to use
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CloudConfig.java From cf-butler with Apache License 2.0 | 8 votes |
@Bean @ConditionalOnProperty(VCAP_SERVICE_VARIABLE) ConnectionFactory connectionFactory() { R2dbcProperties properties = r2dbcProperties(); ConnectionFactoryOptions.Builder builder = ConnectionFactoryOptions .parse(properties.getUrl()).mutate(); String username = properties.getUsername(); if (StringUtils.hasText(username)) { builder.option(ConnectionFactoryOptions.USER, username); } String password = properties.getPassword(); if (StringUtils.hasText(password)) { builder.option(ConnectionFactoryOptions.PASSWORD, password); } String databaseName = properties.getName(); if (StringUtils.hasText(databaseName)) { builder.option(ConnectionFactoryOptions.DATABASE, databaseName); } if (properties.getProperties() != null) { properties.getProperties() .forEach((key, value) -> builder .option(Option.valueOf(key), value)); } return ConnectionFactories.get(builder.build()); }
Example #2
Source File: ImportDataConfiguration.java From sbp with Apache License 2.0 | 6 votes |
@Bean @ConditionalOnProperty(prefix = "spring.flyway", name = "import-data") @DependsOn("flywayInitializer") public FlywayDataImporter flywayDataImporter() { FluentConfiguration flywayConf = plugin != null ? Flyway.configure(plugin.getWrapper().getPluginClassLoader()) : Flyway.configure(); flywayConf.configuration(flyway.getConfiguration()); flywayConf.baselineVersion("0"); flywayConf.baselineOnMigrate(true); flywayConf.locations("classpath:/db_data"); flywayConf.table("_db_data"); Flyway importDataFlyway = new Flyway(flywayConf); FlywayDataImporter importer = new FlywayDataImporter(importDataFlyway); importer.setOrder(Ordered.LOWEST_PRECEDENCE); return importer; }
Example #3
Source File: RedisConfig.java From open-capacity-platform with Apache License 2.0 | 6 votes |
@Primary @Bean("redisTemplate") // 没有此属性就不会装配bean 如果是单个redis 将此注解注释掉 @ConditionalOnProperty(name = "spring.redis.cluster.nodes", matchIfMissing = false) public RedisTemplate<String, Object> getRedisTemplate() { RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>(); redisTemplate.setConnectionFactory(lettuceConnectionFactory); RedisSerializer stringSerializer = new StringRedisSerializer(); // RedisSerializer redisObjectSerializer = new RedisObjectSerializer(); RedisSerializer redisObjectSerializer = new RedisObjectSerializer(); redisTemplate.setKeySerializer(stringSerializer); // key的序列化类型 redisTemplate.setHashKeySerializer(stringSerializer); redisTemplate.setValueSerializer(redisObjectSerializer); // value的序列化类型 redisTemplate.setHashValueSerializer(redisObjectSerializer); // value的序列化类型 redisTemplate.afterPropertiesSet(); redisTemplate.opsForValue().set("hello", "wolrd"); return redisTemplate; }
Example #4
Source File: AtomixClusterServiceAutoConfiguration.java From camel-spring-boot with Apache License 2.0 | 6 votes |
@Bean(name = "atomix-cluster-service") @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) @ConditionalOnProperty(prefix = "camel.component.atomix.cluster.service", name = "mode", havingValue = "node") public CamelClusterService atomixClusterService() { AtomixClusterService service = new AtomixClusterService(); service.setNodes(configuration.getNodes().stream().map(Address::new).collect(Collectors.toList())); ObjectHelper.ifNotEmpty(configuration.isEphemeral(), service::setEphemeral); ObjectHelper.ifNotEmpty(configuration.getId(), service::setId); ObjectHelper.ifNotEmpty(configuration.getAddress(), service::setAddress); ObjectHelper.ifNotEmpty(configuration.getStoragePath(), service::setStoragePath); ObjectHelper.ifNotEmpty(configuration.getStorageLevel(), service::setStorageLevel); ObjectHelper.ifNotEmpty(configuration.getConfigurationUri(), service::setConfigurationUri); ObjectHelper.ifNotEmpty(configuration.getAttributes(), service::setAttributes); ObjectHelper.ifNotEmpty(configuration.getOrder(), service::setOrder); return service; }
Example #5
Source File: MirrorImporterConfiguration.java From hedera-mirror-node with Apache License 2.0 | 6 votes |
@Bean @ConditionalOnProperty(prefix = "hedera.mirror.importer.downloader", name = "cloudProvider", havingValue = "GCP") public S3AsyncClient gcpCloudStorageClient() { log.info("Configured to download from GCP with bucket name '{}'", downloaderProperties.getBucketName()); // Any valid region for aws client. Ignored by GCP. S3AsyncClientBuilder clientBuilder = asyncClientBuilder("us-east-1") .endpointOverride(URI.create(downloaderProperties.getCloudProvider().getEndpoint())); String projectId = downloaderProperties.getGcpProjectId(); if (StringUtils.isNotBlank(projectId)) { clientBuilder.overrideConfiguration(builder -> builder.addExecutionInterceptor(new ExecutionInterceptor() { @Override public SdkHttpRequest modifyHttpRequest( Context.ModifyHttpRequest context, ExecutionAttributes executionAttributes) { return context.httpRequest().toBuilder() .appendRawQueryParameter("userProject", projectId).build(); } })); } return clientBuilder.build(); }
Example #6
Source File: RSocketBrokerAutoConfiguration.java From alibaba-rsocket-broker with Apache License 2.0 | 6 votes |
@Bean @Order(101) @ConditionalOnProperty(name = "rsocket.broker.ssl.key-store") RSocketListenerCustomizer rSocketListenerSSLCustomizer(@Autowired RSocketBrokerProperties properties, @Autowired ResourceLoader resourceLoader) { return builder -> { RSocketBrokerProperties.RSocketSSL rSocketSSL = properties.getSsl(); if (rSocketSSL != null && rSocketSSL.isEnabled() && rSocketSSL.getKeyStore() != null) { try { KeyStore store = KeyStore.getInstance("PKCS12"); store.load(resourceLoader.getResource(rSocketSSL.getKeyStore()).getInputStream(), rSocketSSL.getKeyStorePassword().toCharArray()); String alias = store.aliases().nextElement(); Certificate certificate = store.getCertificate(alias); KeyStore.Entry entry = store.getEntry(alias, new KeyStore.PasswordProtection(rSocketSSL.getKeyStorePassword().toCharArray())); PrivateKey privateKey = ((KeyStore.PrivateKeyEntry) entry).getPrivateKey(); builder.sslContext(certificate, privateKey); builder.listen("tcps", properties.getPort()); } catch (Exception e) { throw new RuntimeException(e); } } }; }
Example #7
Source File: DynamicDataSourceConfiguration.java From open-cloud with MIT License | 5 votes |
@ConditionalOnProperty(value = "opencloud.tenant",matchIfMissing = true) @ConditionalOnMissingBean(DynamicDataSourceAspect.class) @Bean public DynamicDataSourceAspect dynamicDataSourceAspect(OpenTenantProperties openSaasProperties){ logger.info("==> Current tenant is [{}]",openSaasProperties.getTenantId()); return new DynamicDataSourceAspect(openSaasProperties); }
Example #8
Source File: SpringDocConfiguration.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Properties resolver for schema open api customiser. * * @param propertyResolverUtils the property resolver utils * @param openAPIBuilder the open api builder * @return the open api customiser */ @Bean @ConditionalOnProperty(SPRINGDOC_SCHEMA_RESOLVE_PROPERTIES) @Lazy(false) OpenApiCustomiser propertiesResolverForSchema(PropertyResolverUtils propertyResolverUtils, OpenAPIBuilder openAPIBuilder) { return openApi -> { Components components = openApi.getComponents(); Map<String, Schema> schemas = components.getSchemas(); schemas.values().forEach(schema -> openAPIBuilder.resolveProperties(schema, propertyResolverUtils)); }; }
Example #9
Source File: TokenStoreConfig.java From open-capacity-platform with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty(prefix="security.oauth2.token.store",name="type" ,havingValue="jdbc" ,matchIfMissing=false) public JdbcTokenStore jdbcTokenStore(){ // oauth_access_token oauth_refresh_token 创建两张表 // return new JdbcTokenStore( dataSource ) ; return new JdbcTokenStore( dataSource ) ; }
Example #10
Source File: GatewayRSocketAutoConfiguration.java From spring-cloud-rsocket with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty(value = "spring.cloud.gateway.rsocket.broker.actuator.enabled", matchIfMissing = true) public BrokerActuator brokerActuator(BrokerProperties properties, ClusterService clusterService, RoutingTable routingTable) { return new BrokerActuator(properties, clusterService, routingTable); }
Example #11
Source File: GatewayRSocketClientAutoConfiguration.java From spring-cloud-rsocket with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty(name = "spring.cloud.gateway.rsocket.client.auto-connect", matchIfMissing = true) public BrokerClientConnectionListener brokerClientConnectionListener( BrokerClient client, ApplicationEventPublisher publisher) { return new BrokerClientConnectionListener(client, publisher); }
Example #12
Source File: TokenStoreConfig.java From open-capacity-platform with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty(prefix="security.oauth2.token.store",name="type" ,havingValue="jdbc" ,matchIfMissing=false) public JdbcTokenStore jdbcTokenStore(){ // oauth_access_token oauth_refresh_token 创建两张表 // return new JdbcTokenStore( dataSource ) ; return new JdbcTokenStore( dataSource ) ; }
Example #13
Source File: LraServiceAutoConfiguration.java From camel-spring-boot with Apache License 2.0 | 5 votes |
@Bean(name = "lra-service") @ConditionalOnMissingBean(CamelSagaService.class) @ConditionalOnProperty(value = "camel.service.lra.enabled", havingValue = "true") public LRASagaService configureLraSagaService(LraServiceConfiguration configuration) throws Exception { LRASagaService service = new LRASagaService(); service.setCoordinatorUrl(configuration.getCoordinatorUrl()); service.setCoordinatorContextPath(configuration.getCoordinatorContextPath()); service.setLocalParticipantUrl(configuration.getLocalParticipantUrl()); service.setLocalParticipantContextPath(configuration.getLocalParticipantContextPath()); camelContext.addService(service); return service; }
Example #14
Source File: MetricsConfiguration.java From cubeai with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty("jhipster.logging.spectator-metrics.enabled") @ExportMetricReader public SpectatorMetricReader spectatorMetricReader(Registry registry) { log.info("Initializing Spectator Metrics Log reporting"); return new SpectatorMetricReader(registry); }
Example #15
Source File: MetricsConfiguration.java From cubeai with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty("jhipster.logging.spectator-metrics.enabled") @ExportMetricReader public SpectatorMetricReader spectatorMetricReader(Registry registry) { log.info("Initializing Spectator Metrics Log reporting"); return new SpectatorMetricReader(registry); }
Example #16
Source File: ServiceCombDiscoveryClientConfiguration.java From spring-cloud-huawei with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty(value = "spring.cloud.servicecomb.discovery.enabled", matchIfMissing = true) public ServiceCombClient serviceCombClient(ServiceCombDiscoveryProperties serviceCombProperties, ServiceCombAkSkProperties serviceCombAkSkProperties, ServiceCombSSLProperties serviceCombSSLProperties) { ServiceCombClientBuilder builder = new ServiceCombClientBuilder(); if (!StringUtils.isEmpty(serviceCombAkSkProperties.getEnable())) { throw new ServiceCombRuntimeException( "config credentials.enable has change to credentials.enabled ,old names are no longer supported, please change it."); } builder .setUrl(serviceCombProperties.getAddress()) .setServiceCombAkSkProperties(serviceCombAkSkProperties) .setServiceCombSSLProperties(serviceCombSSLProperties); return builder.createServiceCombClient(); }
Example #17
Source File: CasbinAutoConfiguration.java From casbin-spring-boot-starter with Apache License 2.0 | 5 votes |
/** * 自动配置文件存储适配器 */ @Bean @ConditionalOnProperty(name = "casbin.storeType", havingValue = "file") @ConditionalOnMissingBean public Adapter autoConfigFileAdapter(CasbinProperties properties) { // 选择使用文件存储并正确设置了policy文件位置,则创建文件适配器 if (!StringUtils.isEmpty(properties.getPolicy())) { try (InputStream policyInputStream = properties.getPolicyInputStream()) { return new FileAdapter(policyInputStream); } catch (Exception ignored) { } } throw new CasbinAdapterException("Cannot create file adapter, because policy file is not set"); }
Example #18
Source File: AppPublisherConfiguration.java From sofa-dashboard-client with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean @ConditionalOnProperty(prefix = SofaDashboardClientProperties.SOFA_DASHBOARD_PREFIX, value = "arkEnable", matchIfMissing = true) public ArkBizLifecycleHandler bizStateListener(IntrospectBizEndpoint endpoint, Application application) { return new ArkBizLifecycleHandler(endpoint, application); }
Example #19
Source File: TokenStoreConfig.java From open-capacity-platform with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty(prefix="security.oauth2.token.store",name="type" ,havingValue="redis" ,matchIfMissing=true) public RedisTemplateTokenStore redisTokenStore(){ // return new RedisTokenStore( redisTemplate.getConnectionFactory() ) ; //单台redis服务器 Assert.state(redisTemplate != null, "RedisTemplate must be provided"); RedisTemplateTokenStore redisTemplateStore = new RedisTemplateTokenStore() ; redisTemplateStore.setRedisTemplate(redisTemplate); return redisTemplateStore ; }
Example #20
Source File: ApiBootLoggingGlobalLogStorageAutoConfiguration.java From api-boot with Apache License 2.0 | 5 votes |
/** * Instance global log memory mode storage * * @return {@link GlobalLoggingMemoryStorage} */ @Bean @ConditionalOnProperty(prefix = API_BOOT_LOGGING_PREFIX, name = "global-logging-storage-away", havingValue = "memory", matchIfMissing = true) public GlobalLogging globalLogging() { return new GlobalLoggingMemoryStorage(); }
Example #21
Source File: AuthorityMybatisAutoConfiguration.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
/** * 数据权限插件 * * @return DataScopeInterceptor */ @Order(10) @Bean @ConditionalOnProperty(prefix = DatabaseProperties.PREFIX, name = "isDataScope", havingValue = "true", matchIfMissing = true) public DataScopeInterceptor dataScopeInterceptor() { return new DataScopeInterceptor((userId) -> SpringUtils.getBean(UserService.class).getDataScopeById(userId)); }
Example #22
Source File: RSocketBrokerAutoConfiguration.java From alibaba-rsocket-broker with Apache License 2.0 | 5 votes |
@Bean(initMethod = "init", destroyMethod = "close") @ConditionalOnProperty(name = "rsocket.broker.upstream-brokers") public UpstreamBrokerCluster upstreamBrokerCluster(@Autowired RSocketBrokerProperties properties, @Autowired Environment env, @Autowired RSocketFilterChain filterChain, @Autowired ServiceRoutingSelector serviceRoutingSelector, @Autowired RSocketBrokerHandlerRegistry rsocketResponderHandlerRegistry) { RSocketRequesterBySubBroker subBroker = new RSocketRequesterBySubBroker(properties, env, rsocketResponderHandlerRegistry, filterChain, serviceRoutingSelector); return new UpstreamBrokerCluster(subBroker); }
Example #23
Source File: MetricsConfiguration.java From cubeai with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty("jhipster.logging.spectator-metrics.enabled") @ExportMetricReader public SpectatorMetricReader spectatorMetricReader(Registry registry) { log.info("Initializing Spectator Metrics Log reporting"); return new SpectatorMetricReader(registry); }
Example #24
Source File: DruidConfig.java From RuoYi-Vue with MIT License | 5 votes |
@Bean @ConfigurationProperties("spring.datasource.druid.slave") @ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true") public DataSource slaveDataSource(DruidProperties druidProperties) { DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); return druidProperties.dataSource(dataSource); }
Example #25
Source File: MirrorImporterConfiguration.java From hedera-mirror-node with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty(prefix = "hedera.mirror.importer.downloader", name = "cloudProvider", havingValue = "S3", matchIfMissing = true) public S3AsyncClient s3CloudStorageClient() { log.info("Configured to download from S3 in region {} with bucket name '{}'", downloaderProperties.getRegion(), downloaderProperties.getBucketName()); S3AsyncClientBuilder clientBuilder = asyncClientBuilder(downloaderProperties.getRegion()); String endpointOverride = downloaderProperties.getEndpointOverride(); if (endpointOverride != null) { log.info("Overriding s3 client endpoint to {}", endpointOverride); clientBuilder.endpointOverride(URI.create(endpointOverride)); } return clientBuilder.build(); }
Example #26
Source File: SpringCloudAlibabaDubboAutoConfiguration.java From spring-cloud-alibaba-dubbo with Apache License 2.0 | 5 votes |
@ConditionalOnProperty(name = BASE_PACKAGES_PROPERTY_NAME) @ConditionalOnClass(ConfigurationPropertySources.class) @Bean public FeignClientToDubboProviderBeanPostProcessor feignClientToDubboProviderBeanPostProcessor(Environment environment) { Set<String> packagesToScan = environment.getProperty(BASE_PACKAGES_PROPERTY_NAME, Set.class, emptySet()); return new FeignClientToDubboProviderBeanPostProcessor(packagesToScan); }
Example #27
Source File: EnodeAutoConfiguration.java From enode with MIT License | 5 votes |
@Bean(name = "eventSourcingAggregateStorage") @ConditionalOnProperty(prefix = "spring.enode", name = "aggregatestorage", havingValue = "eventsourcing", matchIfMissing = true) public EventSourcingAggregateStorage eventSourcingAggregateStorage( IAggregateRootFactory aggregateRootFactory, IEventStore eventStore, IAggregateSnapshotter aggregateSnapshotter, ITypeNameProvider typeNameProvider) { return new EventSourcingAggregateStorage(eventStore, aggregateRootFactory, aggregateSnapshotter, typeNameProvider); }
Example #28
Source File: EnodeTestDataSourceConfig.java From enode with MIT License | 5 votes |
@Bean("enodeTiDBDataSource") @ConditionalOnProperty(prefix = "spring.enode", name = "eventstore", havingValue = "tidb") public HikariDataSource tidbDataSource() { HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:4000/enode?"); dataSource.setUsername("root"); dataSource.setPassword(""); dataSource.setDriverClassName(com.mysql.cj.jdbc.Driver.class.getName()); return dataSource; }
Example #29
Source File: EnodeEventStoreAutoConfig.java From enode with MIT License | 5 votes |
@Bean @ConditionalOnProperty(prefix = "spring.enode", name = "eventstore", havingValue = "tidb") public TiDBPublishedVersionStore tidbPublishedVersionStore(@Qualifier("enodeTiDBDataSource") DataSource tidbDataSource) { TiDBPublishedVersionStore publishedVersionStore = new TiDBPublishedVersionStore(tidbDataSource, DBConfiguration.mysql()); vertx.deployVerticle(publishedVersionStore, res -> { }); return publishedVersionStore; }
Example #30
Source File: MetricsConfiguration.java From cubeai with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty("jhipster.logging.spectator-metrics.enabled") @ExportMetricReader public SpectatorMetricReader spectatorMetricReader(Registry registry) { log.info("Initializing Spectator Metrics Log reporting"); return new SpectatorMetricReader(registry); }