Skip to content

Commit

Permalink
Switch away from using @ConditionalOnProperty prefix
Browse files Browse the repository at this point in the history
Merge `prefix` into `name` attribute and simplify annotations
where possible.

Closes gh-43703
  • Loading branch information
philwebb committed Jan 6, 2025
1 parent 29e9ce1 commit 4c307d6
Show file tree
Hide file tree
Showing 48 changed files with 101 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static class ConnectionDetails {

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "management.otlp.logging", name = "endpoint")
@ConditionalOnProperty("management.otlp.logging.endpoint")
OtlpLoggingConnectionDetails otlpLoggingConnectionDetails(OtlpLoggingProperties properties) {
return new PropertiesOtlpLoggingConnectionDetails(properties);
}
Expand Down Expand Up @@ -81,8 +81,7 @@ public String getUrl(Transport transport) {
static class Exporters {

@Bean
@ConditionalOnProperty(prefix = "management.otlp.logging", name = "transport", havingValue = "http",
matchIfMissing = true)
@ConditionalOnProperty(name = "management.otlp.logging.transport", havingValue = "http", matchIfMissing = true)
OtlpHttpLogRecordExporter otlpHttpLogRecordExporter(OtlpLoggingProperties properties,
OtlpLoggingConnectionDetails connectionDetails) {
OtlpHttpLogRecordExporterBuilder builder = OtlpHttpLogRecordExporter.builder()
Expand All @@ -95,7 +94,7 @@ OtlpHttpLogRecordExporter otlpHttpLogRecordExporter(OtlpLoggingProperties proper
}

@Bean
@ConditionalOnProperty(prefix = "management.otlp.logging", name = "transport", havingValue = "grpc")
@ConditionalOnProperty(name = "management.otlp.logging.transport", havingValue = "grpc")
OtlpGrpcLogRecordExporter otlpGrpcLogRecordExporter(OtlpLoggingProperties properties,
OtlpLoggingConnectionDetails connectionDetails) {
OtlpGrpcLogRecordExporterBuilder builder = OtlpGrpcLogRecordExporter.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static class ConnectionDetails {

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "management.otlp.tracing", name = "endpoint")
@ConditionalOnProperty("management.otlp.tracing.endpoint")
OtlpTracingConnectionDetails otlpTracingConnectionDetails(OtlpTracingProperties properties) {
return new PropertiesOtlpTracingConnectionDetails(properties);
}
Expand Down Expand Up @@ -79,8 +79,7 @@ public String getUrl(Transport transport) {
static class Exporters {

@Bean
@ConditionalOnProperty(prefix = "management.otlp.tracing", name = "transport", havingValue = "http",
matchIfMissing = true)
@ConditionalOnProperty(name = "management.otlp.tracing.transport", havingValue = "http", matchIfMissing = true)
OtlpHttpSpanExporter otlpHttpSpanExporter(OtlpTracingProperties properties,
OtlpTracingConnectionDetails connectionDetails) {
OtlpHttpSpanExporterBuilder builder = OtlpHttpSpanExporter.builder()
Expand All @@ -93,7 +92,7 @@ OtlpHttpSpanExporter otlpHttpSpanExporter(OtlpTracingProperties properties,
}

@Bean
@ConditionalOnProperty(prefix = "management.otlp.tracing", name = "transport", havingValue = "grpc")
@ConditionalOnProperty(name = "management.otlp.tracing.transport", havingValue = "grpc")
OtlpGrpcSpanExporter otlpGrpcSpanExporter(OtlpTracingProperties properties,
OtlpTracingConnectionDetails connectionDetails) {
OtlpGrpcSpanExporterBuilder builder = OtlpGrpcSpanExporter.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -60,7 +60,7 @@ public ManagementServletContext managementServletContext(WebEndpointProperties p
// Put Servlets and Filters in their own nested class so they don't force early
// instantiation of ManagementServerProperties.
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = "management.server", name = "add-application-context-header", havingValue = "true")
@ConditionalOnProperty(name = "management.server.add-application-context-header", havingValue = "true")
protected static class ApplicationContextFilterConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ SimpleRabbitListenerContainerFactoryConfigurer simpleRabbitListenerContainerFact

@Bean(name = "rabbitListenerContainerFactory")
@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory")
@ConditionalOnProperty(prefix = "spring.rabbitmq.listener", name = "type", havingValue = "simple",
matchIfMissing = true)
@ConditionalOnProperty(name = "spring.rabbitmq.listener.type", havingValue = "simple", matchIfMissing = true)
SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory(
SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory,
ObjectProvider<ContainerCustomizer<SimpleMessageListenerContainer>> simpleContainerCustomizer) {
Expand Down Expand Up @@ -111,7 +110,7 @@ DirectRabbitListenerContainerFactoryConfigurer directRabbitListenerContainerFact

@Bean(name = "rabbitListenerContainerFactory")
@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory")
@ConditionalOnProperty(prefix = "spring.rabbitmq.listener", name = "type", havingValue = "direct")
@ConditionalOnProperty(name = "spring.rabbitmq.listener.type", havingValue = "direct")
DirectRabbitListenerContainerFactory directRabbitListenerContainerFactory(
DirectRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory,
ObjectProvider<ContainerCustomizer<DirectMessageListenerContainer>> directContainerCustomizer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public RabbitTemplate rabbitTemplate(RabbitTemplateConfigurer configurer, Connec

@Bean
@ConditionalOnSingleCandidate(ConnectionFactory.class)
@ConditionalOnProperty(prefix = "spring.rabbitmq", name = "dynamic", matchIfMissing = true)
@ConditionalOnProperty(name = "spring.rabbitmq.dynamic", matchIfMissing = true)
@ConditionalOnMissingBean
public AmqpAdmin amqpAdmin(ConnectionFactory connectionFactory) {
return new RabbitAdmin(connectionFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class RabbitStreamConfiguration {

@Bean(name = "rabbitListenerContainerFactory")
@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory")
@ConditionalOnProperty(prefix = "spring.rabbitmq.listener", name = "type", havingValue = "stream")
@ConditionalOnProperty(name = "spring.rabbitmq.listener.type", havingValue = "stream")
StreamRabbitListenerContainerFactory streamRabbitListenerContainerFactory(Environment rabbitStreamEnvironment,
RabbitProperties properties, ObjectProvider<ConsumerCustomizer> consumerCustomizer,
ObjectProvider<ContainerCustomizer<StreamListenerContainer>> containerCustomizer) {
Expand Down Expand Up @@ -90,7 +90,7 @@ RabbitStreamTemplateConfigurer rabbitStreamTemplateConfigurer(RabbitProperties p

@Bean
@ConditionalOnMissingBean(RabbitStreamOperations.class)
@ConditionalOnProperty(prefix = "spring.rabbitmq.stream", name = "name")
@ConditionalOnProperty(name = "spring.rabbitmq.stream.name")
RabbitStreamTemplate rabbitStreamTemplate(Environment rabbitStreamEnvironment, RabbitProperties properties,
RabbitStreamTemplateConfigurer configurer) {
RabbitStreamTemplate template = new RabbitStreamTemplate(rabbitStreamEnvironment,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,7 +44,7 @@
* @see EnableAspectJAutoProxy
*/
@AutoConfiguration
@ConditionalOnProperty(prefix = "spring.aop", name = "auto", havingValue = "true", matchIfMissing = true)
@ConditionalOnProperty(name = "spring.aop.auto", havingValue = "true", matchIfMissing = true)
public class AopAutoConfiguration {

@Configuration(proxyBeanMethods = false)
Expand All @@ -53,15 +53,14 @@ static class AspectJAutoProxyingConfiguration {

@Configuration(proxyBeanMethods = false)
@EnableAspectJAutoProxy(proxyTargetClass = false)
@ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "false")
@ConditionalOnProperty(name = "spring.aop.proxy-target-class", havingValue = "false")
static class JdkDynamicAutoProxyConfiguration {

}

@Configuration(proxyBeanMethods = false)
@EnableAspectJAutoProxy(proxyTargetClass = true)
@ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "true",
matchIfMissing = true)
@ConditionalOnProperty(name = "spring.aop.proxy-target-class", havingValue = "true", matchIfMissing = true)
static class CglibAutoProxyConfiguration {

}
Expand All @@ -70,8 +69,7 @@ static class CglibAutoProxyConfiguration {

@Configuration(proxyBeanMethods = false)
@ConditionalOnMissingClass("org.aspectj.weaver.Advice")
@ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "true",
matchIfMissing = true)
@ConditionalOnProperty(name = "spring.aop.proxy-target-class", havingValue = "true", matchIfMissing = true)
static class ClassProxyingConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static final class CouchbaseCondition extends AnyNestedCondition {
super(ConfigurationPhase.REGISTER_BEAN);
}

@ConditionalOnProperty(prefix = "spring.couchbase", name = "connection-string")
@ConditionalOnProperty("spring.couchbase.connection-string")
private static final class CouchbaseUrlCondition {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,12 @@ private static final class BootstrapExecutorCondition extends AnyNestedCondition
super(ConfigurationPhase.REGISTER_BEAN);
}

@ConditionalOnProperty(prefix = "spring.data.jpa.repositories", name = "bootstrap-mode",
havingValue = "deferred")
@ConditionalOnProperty(name = "spring.data.jpa.repositories.bootstrap-mode", havingValue = "deferred")
static class DeferredBootstrapMode {

}

@ConditionalOnProperty(prefix = "spring.data.jpa.repositories", name = "bootstrap-mode", havingValue = "lazy")
@ConditionalOnProperty(name = "spring.data.jpa.repositories.bootstrap-mode", havingValue = "lazy")
static class LazyBootstrapMode {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ private static final class JdbcConnectionDetailsCondition {

}

@ConditionalOnProperty(prefix = "spring.flyway", name = "url")
@ConditionalOnProperty("spring.flyway.url")
private static final class FlywayUrlCondition {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void addCorsMappings(CorsRegistry registry) {
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = "spring.graphql.websocket", name = "path")
@ConditionalOnProperty("spring.graphql.websocket.path")
public static class WebSocketConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -49,7 +49,7 @@
@AutoConfiguration(after = { GraphQlAutoConfiguration.class, RSocketMessagingAutoConfiguration.class })
@ConditionalOnClass({ GraphQL.class, GraphQlSource.class, RSocketServer.class, HttpServer.class })
@ConditionalOnBean({ RSocketMessageHandler.class, AnnotatedControllerConfigurer.class })
@ConditionalOnProperty(prefix = "spring.graphql.rsocket", name = "mapping")
@ConditionalOnProperty("spring.graphql.rsocket.mapping")
public class GraphQlRSocketAutoConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void addCorsMappings(CorsRegistry registry) {

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ ServerContainer.class, WebSocketHandler.class })
@ConditionalOnProperty(prefix = "spring.graphql.websocket", name = "path")
@ConditionalOnProperty("spring.graphql.websocket.path")
public static class WebSocketConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -60,8 +60,7 @@ public class HypermediaAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(name = "com.fasterxml.jackson.databind.ObjectMapper")
@ConditionalOnProperty(prefix = "spring.hateoas", name = "use-hal-as-default-json-media-type",
matchIfMissing = true)
@ConditionalOnProperty(name = "spring.hateoas.use-hal-as-default-json-media-type", matchIfMissing = true)
HalConfiguration applicationJsonHalConfiguration() {
return new HalConfiguration().withMediaType(MediaType.APPLICATION_JSON);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,13 @@ static class RemoteRSocketServerAddressConfigured extends AnyNestedCondition {
super(ConfigurationPhase.REGISTER_BEAN);
}

@ConditionalOnProperty(prefix = "spring.integration.rsocket.client", name = "uri")
@ConditionalOnProperty("spring.integration.rsocket.client.uri")
static class WebSocketAddressConfigured {

}

@ConditionalOnProperty(prefix = "spring.integration.rsocket.client", name = { "host", "port" })
@ConditionalOnProperty({ "spring.integration.rsocket.client.host",
"spring.integration.rsocket.client.port" })
static class TcpAddressConfigured {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static class PooledDataSourceCondition extends AnyNestedCondition {
super(ConfigurationPhase.PARSE_CONFIGURATION);
}

@ConditionalOnProperty(prefix = "spring.datasource", name = "type")
@ConditionalOnProperty("spring.datasource.type")
static class ExplicitType {

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -74,7 +74,7 @@ private void validateMBeans() {
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = "spring.datasource.tomcat", name = "jmx-enabled")
@ConditionalOnProperty("spring.datasource.tomcat.jmx-enabled")
@ConditionalOnClass(DataSourceProxy.class)
@ConditionalOnSingleCandidate(DataSource.class)
static class TomcatDataSourceJmxConfiguration {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,7 +41,7 @@
*/
@AutoConfiguration(before = { XADataSourceAutoConfiguration.class, DataSourceAutoConfiguration.class })
@ConditionalOnClass({ DataSource.class, EmbeddedDatabaseType.class })
@ConditionalOnProperty(prefix = "spring.datasource", name = "jndi-name")
@ConditionalOnProperty("spring.datasource.jndi-name")
@EnableConfigurationProperties(DataSourceProperties.class)
public class JndiDataSourceAutoConfiguration {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -115,7 +115,7 @@ public JerseyApplicationPath jerseyApplicationPath() {

@Bean
@ConditionalOnMissingBean(name = "jerseyFilterRegistration")
@ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "filter")
@ConditionalOnProperty(name = "spring.jersey.type", havingValue = "filter")
public FilterRegistrationBean<ServletContainer> jerseyFilterRegistration(JerseyApplicationPath applicationPath) {
FilterRegistrationBean<ServletContainer> registration = new FilterRegistrationBean<>();
registration.setFilter(new ServletContainer(this.config));
Expand All @@ -137,7 +137,7 @@ private String stripPattern(String path) {

@Bean
@ConditionalOnMissingBean(name = "jerseyServletRegistration")
@ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "servlet", matchIfMissing = true)
@ConditionalOnProperty(name = "spring.jersey.type", havingValue = "servlet", matchIfMissing = true)
public ServletRegistrationBean<ServletContainer> jerseyServletRegistration(JerseyApplicationPath applicationPath) {
ServletRegistrationBean<ServletContainer> registration = new ServletRegistrationBean<>(
new ServletContainer(this.config), applicationPath.getUrlMapping());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -89,7 +89,7 @@ static class Jndi {

}

@ConditionalOnProperty(prefix = "spring.jms", name = "jndi-name")
@ConditionalOnProperty("spring.jms.jndi-name")
static class Property {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
class ActiveMQConnectionFactoryConfiguration {

@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "false",
matchIfMissing = true)
@ConditionalOnProperty(name = "spring.activemq.pool.enabled", havingValue = "false", matchIfMissing = true)
static class SimpleConnectionFactoryConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ ConnectionFactory jmsConnectionFactory(ActiveMQProperties properties,
}

@Bean
@ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "false",
matchIfMissing = true)
@ConditionalOnProperty(name = "spring.activemq.pool.enabled", havingValue = "false", matchIfMissing = true)
ActiveMQConnectionFactory nonXaJmsConnectionFactory(ActiveMQProperties properties,
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers,
ActiveMQConnectionDetails connectionDetails) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
class ArtemisConnectionFactoryConfiguration {

@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = "spring.artemis.pool", name = "enabled", havingValue = "false",
matchIfMissing = true)
@ConditionalOnProperty(name = "spring.artemis.pool.enabled", havingValue = "false", matchIfMissing = true)
static class SimpleConnectionFactoryConfiguration {

@Bean(name = "jmsConnectionFactory")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private static final class JdbcConnectionDetailsCondition {

}

@ConditionalOnProperty(prefix = "spring.liquibase", name = "url")
@ConditionalOnProperty("spring.liquibase.url")
private static final class LiquibaseUrlCondition {

}
Expand Down
Loading

0 comments on commit 4c307d6

Please sign in to comment.