diff --git a/autoconfigure-adapter-cassandra/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraInitializer.java b/autoconfigure-adapter-cassandra/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraInitializer.java index 69366b69f..c13c4012b 100644 --- a/autoconfigure-adapter-cassandra/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraInitializer.java +++ b/autoconfigure-adapter-cassandra/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraInitializer.java @@ -4,6 +4,7 @@ import com.datastax.oss.driver.api.core.CqlSessionBuilder; import com.datastax.oss.driver.api.core.config.DriverConfigLoader; +import org.springframework.boot.ssl.SslBundles; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; @@ -20,9 +21,34 @@ public CassandraInitializer(CassandraProperties properties) { @Override public void initialize(GenericApplicationContext context) { - CassandraAutoConfiguration configuration = new CassandraAutoConfiguration(); - context.registerBean(CqlSession.class, () -> configuration.cassandraSession(context.getBean(CqlSessionBuilder.class))); - context.registerBean(CqlSessionBuilder.class, () -> configuration.cassandraSessionBuilder(properties, context.getBean(DriverConfigLoader.class), context.getBeanProvider(CqlSessionBuilderCustomizer.class))); - context.registerBean(DriverConfigLoader.class, () -> configuration.cassandraDriverConfigLoader(properties, context.getBeanProvider(DriverConfigLoaderBuilderCustomizer.class))); + CassandraAutoConfiguration configuration = new CassandraAutoConfiguration(properties); + + context.registerBean( + CqlSession.class, + () -> configuration.cassandraSession(context.getBean(CqlSessionBuilder.class)) + ); + + context.registerBean( + CassandraConnectionDetails.class, + configuration::cassandraConnectionDetails + ); + + context.registerBean( + CqlSessionBuilder.class, + () -> configuration.cassandraSessionBuilder( + context.getBean(DriverConfigLoader.class), + context.getBean(CassandraConnectionDetails.class), + context.getBeanProvider(CqlSessionBuilderCustomizer.class), + context.getBeanProvider(SslBundles.class) + ) + ); + + context.registerBean( + DriverConfigLoader.class, + () -> configuration.cassandraDriverConfigLoader( + context.getBean(CassandraConnectionDetails.class), + context.getBeanProvider(DriverConfigLoaderBuilderCustomizer.class) + ) + ); } } diff --git a/autoconfigure-adapter-cassandra/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataInitializer.java b/autoconfigure-adapter-cassandra/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataInitializer.java index cf283d130..f7cc2dd87 100644 --- a/autoconfigure-adapter-cassandra/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataInitializer.java +++ b/autoconfigure-adapter-cassandra/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataInitializer.java @@ -19,47 +19,104 @@ */ public class CassandraDataInitializer implements ApplicationContextInitializer { - private final CassandraProperties properties; + private final CassandraProperties properties; - public CassandraDataInitializer(CassandraProperties properties) { - this.properties = properties; - } + public CassandraDataInitializer(CassandraProperties properties) { + this.properties = properties; + } - @Override - public void initialize(GenericApplicationContext context) { - Supplier configurationSupplier = () -> new CassandraDataAutoConfiguration(context.getBean(CqlSession.class)); + @Override + public void initialize(GenericApplicationContext context) { + Supplier configurationSupplier = () -> new CassandraDataAutoConfiguration( + context.getBean(CqlSession.class) + ); - context.registerBean(CassandraCustomConversions.class, () -> configurationSupplier.get().cassandraCustomConversions()); - context.registerBean(CassandraMappingContext.class, () -> getCassandraMappingContext(context, configurationSupplier)); - context.registerBean(CassandraConverter.class, () -> configurationSupplier.get().cassandraConverter(context.getBean(CassandraMappingContext.class), context.getBean(CassandraCustomConversions.class))); - context.registerBean(SessionFactoryFactoryBean.class, () -> getCassandraSessionFactoryBean(context, configurationSupplier)); - context.registerBean(CassandraTemplate.class, () -> getCassandraTemplate(context, configurationSupplier)); - } + context.registerBean( + CassandraCustomConversions.class, + () -> configurationSupplier + .get() + .cassandraCustomConversions() + ); + context.registerBean( + CassandraMappingContext.class, + () -> getCassandraMappingContext( + context, + configurationSupplier + ) + ); + context.registerBean( + CassandraConverter.class, + () -> configurationSupplier + .get() + .cassandraConverter( + context.getBean(CassandraMappingContext.class), + context.getBean(CassandraCustomConversions.class) + ) + ); + context.registerBean( + SessionFactoryFactoryBean.class, + () -> getCassandraSessionFactoryBean( + context, + configurationSupplier + ) + ); + context.registerBean( + CassandraTemplate.class, + () -> getCassandraTemplate( + context, + configurationSupplier + ) + ); + } - private CassandraMappingContext getCassandraMappingContext(GenericApplicationContext context, Supplier configurationSupplier) { - try { - return configurationSupplier.get().cassandraMapping(context.getBeanFactory(), context.getBean(CassandraCustomConversions.class)); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - return null; - } + private CassandraMappingContext getCassandraMappingContext( + GenericApplicationContext context, + Supplier configurationSupplier + ) { + try { + return configurationSupplier + .get() + .cassandraMappingContext( + CassandraDataAutoConfiguration.cassandraManagedTypes(context.getBeanFactory()), + context.getBean(CassandraCustomConversions.class) + ); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + return null; + } - private CassandraTemplate getCassandraTemplate(GenericApplicationContext context, Supplier configurationSupplier) { - try { - return configurationSupplier.get().cassandraTemplate(context.getBean(SessionFactory.class), context.getBean(CassandraConverter.class)); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } + private CassandraTemplate getCassandraTemplate( + GenericApplicationContext context, + Supplier configurationSupplier + ) { + try { + return configurationSupplier + .get() + .cassandraTemplate( + context.getBean(SessionFactory.class), + context.getBean(CassandraConverter.class) + ); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } - private SessionFactoryFactoryBean getCassandraSessionFactoryBean(GenericApplicationContext context, Supplier configurationSupplier) { - try { - return configurationSupplier.get().cassandraSessionFactory(context.getEnvironment(), context.getBean(CassandraConverter.class)); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } + private SessionFactoryFactoryBean getCassandraSessionFactoryBean( + GenericApplicationContext context, + Supplier configurationSupplier + ) { + try { + return configurationSupplier + .get() + .cassandraSessionFactory( + context.getEnvironment(), + context.getBean(CassandraConverter.class) + ); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } } diff --git a/autoconfigure-adapter-cassandra/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataInitializer.java b/autoconfigure-adapter-cassandra/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataInitializer.java index 20a839f58..538fec7fb 100644 --- a/autoconfigure-adapter-cassandra/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataInitializer.java +++ b/autoconfigure-adapter-cassandra/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataInitializer.java @@ -14,12 +14,26 @@ */ public class CassandraReactiveDataInitializer implements ApplicationContextInitializer { - @Override - public void initialize(GenericApplicationContext context) { - CassandraReactiveDataAutoConfiguration configuration = new CassandraReactiveDataAutoConfiguration(); + @Override + public void initialize(GenericApplicationContext context) { + CassandraReactiveDataAutoConfiguration configuration = new CassandraReactiveDataAutoConfiguration(); - context.registerBean(ReactiveSession.class, () -> configuration.reactiveCassandraSession(context.getBean(CqlSession.class))); - context.registerBean(ReactiveSessionFactory.class, () -> configuration.reactiveCassandraSessionFactory(context.getBean(ReactiveSession.class))); - context.registerBean(ReactiveCassandraTemplate.class, () -> configuration.reactiveCassandraTemplate(context.getBean(ReactiveSession.class), context.getBean(CassandraConverter.class))); - } + context.registerBean( + ReactiveSession.class, + () -> configuration.reactiveCassandraSession(context.getBean(CqlSession.class)) + ); + + context.registerBean( + ReactiveSessionFactory.class, + () -> configuration.reactiveCassandraSessionFactory(context.getBean(ReactiveSession.class)) + ); + + context.registerBean( + ReactiveCassandraTemplate.class, + () -> configuration.reactiveCassandraTemplate( + context.getBean(ReactiveSession.class), + context.getBean(CassandraConverter.class) + ) + ); + } } diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraInitializer.java deleted file mode 100644 index 69366b69f..000000000 --- a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraInitializer.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.springframework.boot.autoconfigure.cassandra; - -import com.datastax.oss.driver.api.core.CqlSession; -import com.datastax.oss.driver.api.core.CqlSessionBuilder; -import com.datastax.oss.driver.api.core.config.DriverConfigLoader; - -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.support.GenericApplicationContext; - -/** - * {@link ApplicationContextInitializer} adapter for {@link CassandraAutoConfiguration}. - */ -public class CassandraInitializer implements ApplicationContextInitializer { - - private final CassandraProperties properties; - - public CassandraInitializer(CassandraProperties properties) { - this.properties = properties; - } - - @Override - public void initialize(GenericApplicationContext context) { - CassandraAutoConfiguration configuration = new CassandraAutoConfiguration(); - context.registerBean(CqlSession.class, () -> configuration.cassandraSession(context.getBean(CqlSessionBuilder.class))); - context.registerBean(CqlSessionBuilder.class, () -> configuration.cassandraSessionBuilder(properties, context.getBean(DriverConfigLoader.class), context.getBeanProvider(CqlSessionBuilderCustomizer.class))); - context.registerBean(DriverConfigLoader.class, () -> configuration.cassandraDriverConfigLoader(properties, context.getBeanProvider(DriverConfigLoaderBuilderCustomizer.class))); - } -} diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/context/MessageSourceInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/context/MessageSourceInitializer.java index 1e79e3718..1a396a71c 100644 --- a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/context/MessageSourceInitializer.java +++ b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/context/MessageSourceInitializer.java @@ -7,19 +7,27 @@ public class MessageSourceInitializer implements ApplicationContextInitializer { - private final MessageSourceProperties properties; + private final MessageSourceProperties properties; - public MessageSourceInitializer() { - this.properties = new MessageSourceProperties(); - } + public MessageSourceInitializer() { + this.properties = new MessageSourceProperties(); + } - public MessageSourceInitializer(MessageSourceProperties properties) { - this.properties = properties; - } + public MessageSourceInitializer(MessageSourceProperties properties) { + this.properties = properties; + } - @Override - public void initialize(GenericApplicationContext context) { - context.registerBean(AbstractApplicationContext.MESSAGE_SOURCE_BEAN_NAME, MessageSource.class, () -> new MessageSourceAutoConfiguration().messageSource(this.properties)); - context.registerBean(MessageSourceProperties.class, () -> this.properties); - } + @Override + public void initialize(GenericApplicationContext context) { + context.registerBean( + AbstractApplicationContext.MESSAGE_SOURCE_BEAN_NAME, + MessageSource.class, + () -> new MessageSourceAutoConfiguration().messageSource(this.properties) + ); + + context.registerBean( + MessageSourceProperties.class, + () -> this.properties + ); + } } diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataInitializer.java deleted file mode 100644 index cf283d130..000000000 --- a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataInitializer.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.springframework.boot.autoconfigure.data.cassandra; - -import org.springframework.boot.autoconfigure.cassandra.CassandraProperties; -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.support.GenericApplicationContext; -import org.springframework.data.cassandra.SessionFactory; -import org.springframework.data.cassandra.config.SessionFactoryFactoryBean; -import org.springframework.data.cassandra.core.CassandraTemplate; -import org.springframework.data.cassandra.core.convert.CassandraConverter; -import org.springframework.data.cassandra.core.convert.CassandraCustomConversions; -import org.springframework.data.cassandra.core.mapping.CassandraMappingContext; - -import java.util.function.Supplier; - -import com.datastax.oss.driver.api.core.CqlSession; - -/** - * {@link ApplicationContextInitializer} adapter for {@link CassandraReactiveDataAutoConfiguration}. - */ -public class CassandraDataInitializer implements ApplicationContextInitializer { - - private final CassandraProperties properties; - - public CassandraDataInitializer(CassandraProperties properties) { - this.properties = properties; - } - - @Override - public void initialize(GenericApplicationContext context) { - Supplier configurationSupplier = () -> new CassandraDataAutoConfiguration(context.getBean(CqlSession.class)); - - context.registerBean(CassandraCustomConversions.class, () -> configurationSupplier.get().cassandraCustomConversions()); - context.registerBean(CassandraMappingContext.class, () -> getCassandraMappingContext(context, configurationSupplier)); - context.registerBean(CassandraConverter.class, () -> configurationSupplier.get().cassandraConverter(context.getBean(CassandraMappingContext.class), context.getBean(CassandraCustomConversions.class))); - context.registerBean(SessionFactoryFactoryBean.class, () -> getCassandraSessionFactoryBean(context, configurationSupplier)); - context.registerBean(CassandraTemplate.class, () -> getCassandraTemplate(context, configurationSupplier)); - } - - private CassandraMappingContext getCassandraMappingContext(GenericApplicationContext context, Supplier configurationSupplier) { - try { - return configurationSupplier.get().cassandraMapping(context.getBeanFactory(), context.getBean(CassandraCustomConversions.class)); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - return null; - } - - private CassandraTemplate getCassandraTemplate(GenericApplicationContext context, Supplier configurationSupplier) { - try { - return configurationSupplier.get().cassandraTemplate(context.getBean(SessionFactory.class), context.getBean(CassandraConverter.class)); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - private SessionFactoryFactoryBean getCassandraSessionFactoryBean(GenericApplicationContext context, Supplier configurationSupplier) { - try { - return configurationSupplier.get().cassandraSessionFactory(context.getEnvironment(), context.getBean(CassandraConverter.class)); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } -} diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticSearchDataInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticSearchDataInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticSearchDataInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticSearchDataInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/redis/ClusterInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/redis/ClusterInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisRedisInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisRedisInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceRedisInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceRedisInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/redis/SentinelInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/data/redis/SentinelInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration_GenericInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration_GenericInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration_HikariInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration_HikariInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfigurationInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfigurationInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfigurationInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfigurationInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfigurationInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfigurationInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfigurationInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfigurationInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_CommonsDbcp2PoolDataSourceMetadataProviderConfigurationInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_CommonsDbcp2PoolDataSourceMetadataProviderConfigurationInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_HikariPoolDataSourceMetadataProviderConfigurationInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_HikariPoolDataSourceMetadataProviderConfigurationInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_TomcatDataSourcePoolMetadataProviderConfigurationInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_TomcatDataSourcePoolMetadataProviderConfigurationInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqConfigurationInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqConfigurationInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/r2dbc/R2dbcInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/r2dbc/R2dbcInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveWebInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveWebInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletWebInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletWebInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/AbstractCodecInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/AbstractCodecInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/FormCodecInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/FormCodecInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/JacksonJsonCodecInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/JacksonJsonCodecInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/KotlinSerializationCodecInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/KotlinSerializationCodecInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/MultipartCodecInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/MultipartCodecInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ProtobufCodecInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ProtobufCodecInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ResourceCodecInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ResourceCodecInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/StringCodecInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/StringCodecInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ReactiveWebClientBuilderInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ReactiveWebClientBuilderInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/AtomConverterInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/AtomConverterInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/FormConverterInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/FormConverterInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/JacksonJsonConverterInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/JacksonJsonConverterInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/KotlinSerializationConverterInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/KotlinSerializationConverterInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ResourceConverterInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ResourceConverterInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/RssConverterInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/RssConverterInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/StringConverterInitializer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/autoconfigure/web/servlet/StringConverterInitializer.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/context/properties/FunctionalConfigurationPropertiesBinder.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/context/properties/FunctionalConfigurationPropertiesBinder.java index 4e904a771..5ef7fb53e 100644 --- a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/context/properties/FunctionalConfigurationPropertiesBinder.java +++ b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/context/properties/FunctionalConfigurationPropertiesBinder.java @@ -32,24 +32,38 @@ */ public class FunctionalConfigurationPropertiesBinder { - private final ConfigurableApplicationContext context; + private final ConfigurableApplicationContext context; - private final Binder binder; + private final Binder binder; - public FunctionalConfigurationPropertiesBinder(ConfigurableApplicationContext context) { - PropertySources propertySources = new FunctionalPropertySourcesDeducer(context).getPropertySources(); - this.context = context; - this.binder = new Binder(ConfigurationPropertySources.from(propertySources), - new PropertySourcesPlaceholdersResolver(propertySources), - null, - (registry) -> context.getBeanFactory().copyRegisteredEditorsTo(registry)); - } + public FunctionalConfigurationPropertiesBinder(ConfigurableApplicationContext context) { + PropertySources propertySources = new FunctionalPropertySourcesDeducer(context).getPropertySources(); + this.context = context; + this.binder = new Binder( + ConfigurationPropertySources.from(propertySources), + new PropertySourcesPlaceholdersResolver(propertySources), + null, + (registry) -> context + .getBeanFactory() + .copyRegisteredEditorsTo(registry) + ); + } - public BindResult bind(String prefix, Bindable target) { - UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter(); - NoUnboundElementsBindHandler handler = new NoUnboundElementsBindHandler(new IgnoreTopLevelConverterNotFoundBindHandler(), filter); - return binder.bind(prefix, target, handler); - } + public BindResult bind( + String prefix, + Bindable target + ) { + UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter(); + NoUnboundElementsBindHandler handler = new NoUnboundElementsBindHandler( + new IgnoreTopLevelConverterNotFoundBindHandler(), + filter + ); + return binder.bind( + prefix, + target, + handler + ); + } } diff --git a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/context/properties/FunctionalPropertySourcesDeducer.java b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/context/properties/FunctionalPropertySourcesDeducer.java index 5670030db..8653a1eee 100644 --- a/autoconfigure-adapter-context/src/main/java/org/springframework/boot/context/properties/FunctionalPropertySourcesDeducer.java +++ b/autoconfigure-adapter-context/src/main/java/org/springframework/boot/context/properties/FunctionalPropertySourcesDeducer.java @@ -14,26 +14,26 @@ */ public class FunctionalPropertySourcesDeducer { - private final ApplicationContext applicationContext; + private final ApplicationContext applicationContext; - FunctionalPropertySourcesDeducer(ApplicationContext applicationContext) { - this.applicationContext = applicationContext; - } + FunctionalPropertySourcesDeducer(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } - public PropertySources getPropertySources() { - MutablePropertySources sources = extractEnvironmentPropertySources(); - if (sources != null) { - return sources; - } - throw new IllegalStateException("Unable to obtain PropertySources from " - + "PropertySourcesPlaceholderConfigurer or Environment"); - } + public PropertySources getPropertySources() { + MutablePropertySources sources = extractEnvironmentPropertySources(); + if (sources != null) { + return sources; + } + throw new IllegalStateException("Unable to obtain PropertySources from " + + "PropertySourcesPlaceholderConfigurer or Environment"); + } - private MutablePropertySources extractEnvironmentPropertySources() { - Environment environment = this.applicationContext.getEnvironment(); - if (environment instanceof ConfigurableEnvironment) { - return ((ConfigurableEnvironment) environment).getPropertySources(); - } - return null; - } + private MutablePropertySources extractEnvironmentPropertySources() { + Environment environment = this.applicationContext.getEnvironment(); + if (environment instanceof ConfigurableEnvironment) { + return ((ConfigurableEnvironment) environment).getPropertySources(); + } + return null; + } } diff --git a/autoconfigure-adapter-elasticsearch/build.gradle.kts b/autoconfigure-adapter-elasticsearch/build.gradle.kts index d8b327ad2..617c67b19 100644 --- a/autoconfigure-adapter-elasticsearch/build.gradle.kts +++ b/autoconfigure-adapter-elasticsearch/build.gradle.kts @@ -8,6 +8,9 @@ dependencies { api("org.springframework.boot:spring-boot-autoconfigure") compileOnly("org.springframework.data:spring-data-elasticsearch") + compileOnly("org.elasticsearch.client:elasticsearch-rest-high-level-client:7.17.5") { + exclude("commons-logging:commons-logging") + } } repositories { diff --git a/autoconfigure-adapter-elasticsearch/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticSearchDataInitializer.java b/autoconfigure-adapter-elasticsearch/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticSearchDataInitializer.java index 3e574c3a2..373cfe86f 100644 --- a/autoconfigure-adapter-elasticsearch/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticSearchDataInitializer.java +++ b/autoconfigure-adapter-elasticsearch/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticSearchDataInitializer.java @@ -4,9 +4,9 @@ import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; import org.springframework.data.elasticsearch.client.ClientConfiguration; -import org.springframework.data.elasticsearch.client.RestClients; +import org.springframework.data.elasticsearch.client.erhlc.RestClients; -public class ElasticSearchDataInitializer implements ApplicationContextInitializer { +public class ElasticSearchDataInitializer implements ApplicationContextInitializer { private final ClientConfiguration clientConfiguration; @@ -14,8 +14,14 @@ public ElasticSearchDataInitializer(ClientConfiguration clientConfiguration) { this.clientConfiguration = clientConfiguration; } + @SuppressWarnings("deprecation") @Override public void initialize(GenericApplicationContext context) { - context.registerBean(RestHighLevelClient.class, () -> RestClients.create(clientConfiguration).rest()); + context.registerBean( + RestHighLevelClient.class, + () -> RestClients + .create(clientConfiguration) + .rest() + ); } } diff --git a/autoconfigure-adapter-elasticsearch/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticSearchDataInitializer.java b/autoconfigure-adapter-elasticsearch/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticSearchDataInitializer.java index dbb9c22a7..b6ae9598f 100644 --- a/autoconfigure-adapter-elasticsearch/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticSearchDataInitializer.java +++ b/autoconfigure-adapter-elasticsearch/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticSearchDataInitializer.java @@ -3,10 +3,10 @@ import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; import org.springframework.data.elasticsearch.client.ClientConfiguration; -import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient; -import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients; +import org.springframework.data.elasticsearch.client.erhlc.ReactiveElasticsearchClient; +import org.springframework.data.elasticsearch.client.erhlc.ReactiveRestClients; -public class ReactiveElasticSearchDataInitializer implements ApplicationContextInitializer { +public class ReactiveElasticSearchDataInitializer implements ApplicationContextInitializer { private final ClientConfiguration clientConfiguration; @@ -14,8 +14,12 @@ public ReactiveElasticSearchDataInitializer(ClientConfiguration clientConfigurat this.clientConfiguration = clientConfiguration; } + @SuppressWarnings("deprecation") @Override public void initialize(GenericApplicationContext context) { - context.registerBean(ReactiveElasticsearchClient.class, () -> ReactiveRestClients.create(clientConfiguration)); + context.registerBean( + ReactiveElasticsearchClient.class, + () -> ReactiveRestClients.create(clientConfiguration) + ); } } diff --git a/autoconfigure-adapter-jackson/build.gradle.kts b/autoconfigure-adapter-jackson/build.gradle.kts index b2a770852..44ab89194 100644 --- a/autoconfigure-adapter-jackson/build.gradle.kts +++ b/autoconfigure-adapter-jackson/build.gradle.kts @@ -7,6 +7,7 @@ dependencies { api("org.springframework.boot:spring-boot") api("org.springframework.boot:spring-boot-autoconfigure") + compileOnly("org.springframework:spring-web") compileOnly("com.fasterxml.jackson.core:jackson-databind") } diff --git a/autoconfigure-adapter-jackson/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonInitializer.java b/autoconfigure-adapter-jackson/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonInitializer.java index 02841b953..be2397db2 100644 --- a/autoconfigure-adapter-jackson/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonInitializer.java +++ b/autoconfigure-adapter-jackson/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonInitializer.java @@ -22,6 +22,7 @@ import java.util.ArrayList; +import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.context.ApplicationContextInitializer; @@ -33,18 +34,43 @@ */ public class JacksonInitializer implements ApplicationContextInitializer { - private final JacksonProperties properties; + private final JacksonProperties properties; - public JacksonInitializer(JacksonProperties properties) { - this.properties = properties; - } + public JacksonInitializer(JacksonProperties properties) { + this.properties = properties; + } - @Override - public void initialize(GenericApplicationContext context) { - context.registerBean(Jackson2ObjectMapperBuilderCustomizer.class, () -> new Jackson2ObjectMapperBuilderCustomizerConfiguration().standardJacksonObjectMapperBuilderCustomizer(context, this.properties)); - JacksonObjectMapperBuilderConfiguration configuration = new JacksonObjectMapperBuilderConfiguration(); - context.registerBean(Jackson2ObjectMapperBuilder.class, () -> - configuration.jacksonObjectMapperBuilder(context, new ArrayList<>(context.getBeansOfType(Jackson2ObjectMapperBuilderCustomizer.class).values()))); - context.registerBean(ObjectMapper.class, () -> new JacksonObjectMapperConfiguration().jacksonObjectMapper(context.getBean(Jackson2ObjectMapperBuilder.class))); - } + @Override + public void initialize(GenericApplicationContext context) { + context.registerBean( + Jackson2ObjectMapperBuilderCustomizer.class, + () -> new Jackson2ObjectMapperBuilderCustomizerConfiguration() + .standardJacksonObjectMapperBuilderCustomizer( + this.properties, + context.getBeanProvider(Module.class) + ) + ); + + JacksonObjectMapperBuilderConfiguration configuration = new JacksonObjectMapperBuilderConfiguration(); + context.registerBean( + Jackson2ObjectMapperBuilder.class, + () -> + configuration.jacksonObjectMapperBuilder( + context, + new ArrayList<>( + context + .getBeansOfType(Jackson2ObjectMapperBuilderCustomizer.class) + .values() + ) + ) + ); + + context.registerBean( + ObjectMapper.class, + () -> new JacksonObjectMapperConfiguration() + .jacksonObjectMapper( + context.getBean(Jackson2ObjectMapperBuilder.class) + ) + ); + } } diff --git a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration_GenericInitializer.java b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration_GenericInitializer.java index 480f50ef9..8dced3ec8 100644 --- a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration_GenericInitializer.java +++ b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration_GenericInitializer.java @@ -2,22 +2,37 @@ import java.lang.Override; import javax.sql.DataSource; + import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; public class DataSourceConfiguration_GenericInitializer implements ApplicationContextInitializer { - private final DataSourceProperties dataSourceProperties; + private final DataSourceProperties dataSourceProperties; + + public DataSourceConfiguration_GenericInitializer(DataSourceProperties dataSourceProperties) { + this.dataSourceProperties = dataSourceProperties; + } - public DataSourceConfiguration_GenericInitializer(DataSourceProperties dataSourceProperties) { - this.dataSourceProperties = dataSourceProperties; - } + @Override + public void initialize(GenericApplicationContext context) { + if ( + context + .getBeanFactory() + .getBeanNamesForType(DataSourceConfiguration.Generic.class).length == 0 + ) { + context.registerBean( + DataSourceConfiguration.Generic.class, + DataSourceConfiguration.Generic::new + ); - @Override - public void initialize(GenericApplicationContext context) { - if (context.getBeanFactory().getBeanNamesForType(DataSourceConfiguration.Generic.class).length==0) { - context.registerBean(DataSourceConfiguration.Generic.class, () -> new DataSourceConfiguration.Generic()); - context.registerBean("dataSource", DataSource.class, () -> context.getBean(DataSourceConfiguration.Generic.class).dataSource(this.dataSourceProperties)); + context.registerBean( + "dataSource", + DataSource.class, + () -> context + .getBean(DataSourceConfiguration.Generic.class) + .dataSource(this.dataSourceProperties) + ); + } } - } } diff --git a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration_HikariInitializer.java b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration_HikariInitializer.java index 2f5389e24..62cdebefa 100644 --- a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration_HikariInitializer.java +++ b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration_HikariInitializer.java @@ -1,23 +1,43 @@ package org.springframework.boot.autoconfigure.jdbc; import com.zaxxer.hikari.HikariDataSource; + import java.lang.Override; + import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; public class DataSourceConfiguration_HikariInitializer implements ApplicationContextInitializer { - private final DataSourceProperties dataSourceProperties; + private final DataSourceProperties dataSourceProperties; + + public DataSourceConfiguration_HikariInitializer(DataSourceProperties dataSourceProperties) { + this.dataSourceProperties = dataSourceProperties; + } - public DataSourceConfiguration_HikariInitializer(DataSourceProperties dataSourceProperties) { - this.dataSourceProperties = dataSourceProperties; - } + @Override + public void initialize(GenericApplicationContext context) { + if ( + context + .getBeanFactory() + .getBeanNamesForType(DataSourceConfiguration.Hikari.class).length == 0 + ) { + context.registerBean( + DataSourceConfiguration.Hikari.class, + DataSourceConfiguration.Hikari::new + ); - @Override - public void initialize(GenericApplicationContext context) { - if (context.getBeanFactory().getBeanNamesForType(DataSourceConfiguration.Hikari.class).length==0) { - context.registerBean(DataSourceConfiguration.Hikari.class, () -> new DataSourceConfiguration.Hikari()); - context.registerBean("dataSource", HikariDataSource.class, () -> context.getBean(DataSourceConfiguration.Hikari.class).dataSource(this.dataSourceProperties), def -> { def.setFactoryMethodName("dataSource"); def.setFactoryBeanName(DataSourceConfiguration.Hikari.class.getName());}); + context.registerBean( + "dataSource", + HikariDataSource.class, + () -> context + .getBean(DataSourceConfiguration.Hikari.class) + .dataSource(this.dataSourceProperties), + def -> { + def.setFactoryMethodName("dataSource"); + def.setFactoryBeanName(DataSourceConfiguration.Hikari.class.getName()); + } + ); + } } - } } diff --git a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java index 916a7566d..c48bd747a 100644 --- a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java +++ b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java @@ -49,156 +49,223 @@ */ class DataSourceInitializer { - private static final Log logger = LogFactory.getLog(DataSourceInitializer.class); - - private final DataSource dataSource; - - private final DataSourceProperties properties; - - private final ResourceLoader resourceLoader; - - /** - * Create a new instance with the {@link DataSource} to initialize and its matching - * {@link DataSourceProperties configuration}. - * @param dataSource the datasource to initialize - * @param properties the matching configuration - * @param resourceLoader the resource loader to use (can be null) - */ - DataSourceInitializer(DataSource dataSource, DataSourceProperties properties, ResourceLoader resourceLoader) { - this.dataSource = dataSource; - this.properties = properties; - this.resourceLoader = (resourceLoader != null) ? resourceLoader : new DefaultResourceLoader(null); - } - - /** - * Create a new instance with the {@link DataSource} to initialize and its matching - * {@link DataSourceProperties configuration}. - * @param dataSource the datasource to initialize - * @param properties the matching configuration - */ - DataSourceInitializer(DataSource dataSource, DataSourceProperties properties) { - this(dataSource, properties, null); - } - - DataSource getDataSource() { - return this.dataSource; - } - - /** - * Create the schema if necessary. - * @return {@code true} if the schema was created - * @see DataSourceProperties#getSchema() - */ - boolean createSchema() { - List scripts = getScripts("spring.datasource.schema", this.properties.getSchema(), "schema"); - if (!scripts.isEmpty()) { - if (!isEnabled()) { - logger.debug("Initialization disabled (not running DDL scripts)"); - return false; - } - String username = this.properties.getSchemaUsername(); - String password = this.properties.getSchemaPassword(); - runScripts(scripts, username, password); - } - return !scripts.isEmpty(); - } - - /** - * Initialize the schema if necessary. - * @see DataSourceProperties#getData() - */ - void initSchema() { - List scripts = getScripts("spring.datasource.data", this.properties.getData(), "data"); - if (!scripts.isEmpty()) { - if (!isEnabled()) { - logger.debug("Initialization disabled (not running data scripts)"); - return; - } - String username = this.properties.getDataUsername(); - String password = this.properties.getDataPassword(); - runScripts(scripts, username, password); - } - } - - private boolean isEnabled() { - DataSourceInitializationMode mode = this.properties.getInitializationMode(); - if (mode == DataSourceInitializationMode.NEVER) { - return false; - } - if (mode == DataSourceInitializationMode.EMBEDDED && !isEmbedded()) { - return false; - } - return true; - } - - private boolean isEmbedded() { - try { - return EmbeddedDatabaseConnection.isEmbedded(this.dataSource); - } - catch (Exception ex) { - logger.debug("Could not determine if datasource is embedded", ex); - return false; - } - } - - private List getScripts(String propertyName, List resources, String fallback) { - if (resources != null) { - return getResources(propertyName, resources, true); - } - String platform = this.properties.getPlatform(); - List fallbackResources = new ArrayList<>(); - fallbackResources.add("classpath*:" + fallback + "-" + platform + ".sql"); - fallbackResources.add("classpath*:" + fallback + ".sql"); - return getResources(propertyName, fallbackResources, false); - } - - private List getResources(String propertyName, List locations, boolean validate) { - List resources = new ArrayList<>(); - for (String location : locations) { - for (Resource resource : doGetResources(location)) { - if (resource.exists()) { - resources.add(resource); - } - else if (validate) { - throw new InvalidConfigurationPropertyValueException(propertyName, resource, - "The specified resource does not exist."); - } - } - } - return resources; - } - - private Resource[] doGetResources(String location) { - try { - SortedResourcesFactoryBean factory = new SortedResourcesFactoryBean(this.resourceLoader, - Collections.singletonList(location)); - factory.afterPropertiesSet(); - return factory.getObject(); - } - catch (Exception ex) { - throw new IllegalStateException("Unable to load resources from " + location, ex); - } - } - - private void runScripts(List resources, String username, String password) { - if (resources.isEmpty()) { - return; - } - ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); - populator.setContinueOnError(this.properties.isContinueOnError()); - populator.setSeparator(this.properties.getSeparator()); - if (this.properties.getSqlScriptEncoding() != null) { - populator.setSqlScriptEncoding(this.properties.getSqlScriptEncoding().name()); - } - for (Resource resource : resources) { - populator.addScript(resource); - } - DataSource dataSource = this.dataSource; - if (StringUtils.hasText(username) && StringUtils.hasText(password)) { - dataSource = DataSourceBuilder.create(this.properties.getClassLoader()) - .driverClassName(this.properties.determineDriverClassName()).url(this.properties.determineUrl()) - .username(username).password(password).build(); - } - DatabasePopulatorUtils.execute(populator, dataSource); - } + private static final Log logger = LogFactory.getLog(DataSourceInitializer.class); + + private final DataSource dataSource; + + private final DataSourceProperties properties; + + private final ResourceLoader resourceLoader; + + /** + * Create a new instance with the {@link DataSource} to initialize and its matching + * {@link DataSourceProperties configuration}. + * + * @param dataSource the datasource to initialize + * @param properties the matching configuration + * @param resourceLoader the resource loader to use (can be null) + */ + DataSourceInitializer( + DataSource dataSource, + DataSourceProperties properties, + ResourceLoader resourceLoader + ) { + this.dataSource = dataSource; + this.properties = properties; + this.resourceLoader = (resourceLoader != null) ? resourceLoader : new DefaultResourceLoader(null); + } + + /** + * Create a new instance with the {@link DataSource} to initialize and its matching + * {@link DataSourceProperties configuration}. + * + * @param dataSource the datasource to initialize + * @param properties the matching configuration + */ + DataSourceInitializer( + DataSource dataSource, + DataSourceProperties properties + ) { + this( + dataSource, + properties, + null + ); + } + + DataSource getDataSource() { + return this.dataSource; + } + + /** + * Create the schema if necessary. + * + * @return {@code true} if the schema was created + * @see DataSourceProperties#getSchema() + */ + boolean createSchema() { + List scripts = getScripts( + "spring.datasource.schema", + this.properties.getSchema(), + "schema" + ); + if (!scripts.isEmpty()) { + if (!isEnabled()) { + logger.debug("Initialization disabled (not running DDL scripts)"); + return false; + } + String username = this.properties.getSchemaUsername(); + String password = this.properties.getSchemaPassword(); + runScripts( + scripts, + username, + password + ); + } + return !scripts.isEmpty(); + } + + /** + * Initialize the schema if necessary. + * + * @see DataSourceProperties#getData() + */ + void initSchema() { + List scripts = getScripts( + "spring.datasource.data", + this.properties.getData(), + "data" + ); + if (!scripts.isEmpty()) { + if (!isEnabled()) { + logger.debug("Initialization disabled (not running data scripts)"); + return; + } + String username = this.properties.getDataUsername(); + String password = this.properties.getDataPassword(); + runScripts( + scripts, + username, + password + ); + } + } + + private boolean isEnabled() { + DataSourceInitializationMode mode = this.properties.getInitializationMode(); + if (mode == DataSourceInitializationMode.NEVER) { + return false; + } + if (mode == DataSourceInitializationMode.EMBEDDED && !isEmbedded()) { + return false; + } + return true; + } + + private boolean isEmbedded() { + try { + return EmbeddedDatabaseConnection.isEmbedded(this.dataSource); + } catch (Exception ex) { + logger.debug( + "Could not determine if datasource is embedded", + ex + ); + return false; + } + } + + private List getScripts( + String propertyName, + List resources, + String fallback + ) { + if (resources != null) { + return getResources( + propertyName, + resources, + true + ); + } + String platform = this.properties.getPlatform(); + List fallbackResources = new ArrayList<>(); + fallbackResources.add("classpath*:" + fallback + "-" + platform + ".sql"); + fallbackResources.add("classpath*:" + fallback + ".sql"); + return getResources( + propertyName, + fallbackResources, + false + ); + } + + private List getResources( + String propertyName, + List locations, + boolean validate + ) { + List resources = new ArrayList<>(); + for (String location : locations) { + for (Resource resource : doGetResources(location)) { + if (resource.exists()) { + resources.add(resource); + } else if (validate) { + throw new InvalidConfigurationPropertyValueException(propertyName, + resource, + "The specified resource does not exist." + ); + } + } + } + return resources; + } + + private Resource[] doGetResources(String location) { + try { + SortedResourcesFactoryBean factory = new SortedResourcesFactoryBean( + this.resourceLoader, + Collections.singletonList(location) + ); + factory.afterPropertiesSet(); + return factory.getObject(); + } catch (Exception ex) { + throw new IllegalStateException( + "Unable to load resources from " + location, + ex + ); + } + } + + private void runScripts( + List resources, + String username, + String password + ) { + if (resources.isEmpty()) { + return; + } + ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); + populator.setContinueOnError(this.properties.isContinueOnError()); + populator.setSeparator(this.properties.getSeparator()); + if (this.properties.getSqlScriptEncoding() != null) { + populator.setSqlScriptEncoding(this.properties + .getSqlScriptEncoding() + .name()); + } + for (Resource resource : resources) { + populator.addScript(resource); + } + DataSource dataSource = this.dataSource; + if (StringUtils.hasText(username) && StringUtils.hasText(password)) { + dataSource = DataSourceBuilder + .create(this.properties.getClassLoader()) + .driverClassName(this.properties.determineDriverClassName()) + .url(this.properties.determineUrl()) + .username(username) + .password(password) + .build(); + } + DatabasePopulatorUtils.execute( + populator, + dataSource + ); + } } diff --git a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfigurationInitializer.java b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfigurationInitializer.java index 62a98e04c..fac8a889f 100644 --- a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfigurationInitializer.java +++ b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfigurationInitializer.java @@ -12,12 +12,34 @@ public class DataSourceTransactionManagerAutoConfigurationInitializer implements ApplicationContextInitializer { - @Override - public void initialize(GenericApplicationContext context) { - if (context.getBeanFactory().getBeanNamesForType(DataSourceTransactionManagerAutoConfiguration.class).length==0) { - context.registerBean(DataSourceTransactionManagerAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration::new); - context.registerBean(DataSourceTransactionManagerAutoConfiguration.JdbcTransactionManagerConfiguration.class, DataSourceTransactionManagerAutoConfiguration.JdbcTransactionManagerConfiguration::new); - context.registerBean("transactionManager", DataSourceTransactionManager.class, () -> context.getBean(DataSourceTransactionManagerAutoConfiguration.JdbcTransactionManagerConfiguration.class).transactionManager(context.getBean(Environment.class), context.getBean(DataSource.class),context.getBeanProvider(TransactionManagerCustomizers.class))); + @Override + public void initialize(GenericApplicationContext context) { + if ( + context + .getBeanFactory() + .getBeanNamesForType(DataSourceTransactionManagerAutoConfiguration.class).length == 0 + ) { + context.registerBean( + DataSourceTransactionManagerAutoConfiguration.class, + DataSourceTransactionManagerAutoConfiguration::new + ); + + context.registerBean( + DataSourceTransactionManagerAutoConfiguration.JdbcTransactionManagerConfiguration.class, + DataSourceTransactionManagerAutoConfiguration.JdbcTransactionManagerConfiguration::new + ); + + context.registerBean( + "transactionManager", + DataSourceTransactionManager.class, + () -> context + .getBean(DataSourceTransactionManagerAutoConfiguration.JdbcTransactionManagerConfiguration.class) + .transactionManager( + context.getBean(Environment.class), + context.getBean(DataSource.class), + context.getBeanProvider(TransactionManagerCustomizers.class) + ) + ); + } } - } } diff --git a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfigurationInitializer.java b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfigurationInitializer.java index 2a4435265..2ae22b018 100644 --- a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfigurationInitializer.java +++ b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfigurationInitializer.java @@ -6,16 +6,25 @@ public class EmbeddedDataSourceConfigurationInitializer implements ApplicationContextInitializer { - private final DataSourceProperties dataSourceProperties; + private final DataSourceProperties dataSourceProperties; - public EmbeddedDataSourceConfigurationInitializer(DataSourceProperties dataSourceProperties) { - this.dataSourceProperties = dataSourceProperties; - } + public EmbeddedDataSourceConfigurationInitializer(DataSourceProperties dataSourceProperties) { + this.dataSourceProperties = dataSourceProperties; + } - @Override - public void initialize(GenericApplicationContext context) { - if (context.getBeanFactory().getBeanNamesForType(EmbeddedDataSourceConfiguration.class).length == 0) { - context.registerBean("dataSource", EmbeddedDatabase.class, () -> new EmbeddedDataSourceConfiguration().dataSource(this.dataSourceProperties), def -> def.setDestroyMethodName("shutdown")); + @Override + public void initialize(GenericApplicationContext context) { + if ( + context + .getBeanFactory() + .getBeanNamesForType(EmbeddedDataSourceConfiguration.class).length == 0 + ) { + context.registerBean( + "dataSource", + EmbeddedDatabase.class, + () -> new EmbeddedDataSourceConfiguration().dataSource(this.dataSourceProperties), + def -> def.setDestroyMethodName("shutdown") + ); + } } - } } diff --git a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfigurationInitializer.java b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfigurationInitializer.java index 19a6dfd19..a4abcd0a9 100644 --- a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfigurationInitializer.java +++ b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfigurationInitializer.java @@ -2,22 +2,35 @@ import java.lang.Override; import javax.sql.DataSource; + import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; import org.springframework.jdbc.core.JdbcTemplate; public class JdbcTemplateConfigurationInitializer implements ApplicationContextInitializer { - private final JdbcProperties jdbcProperties; + private final JdbcProperties jdbcProperties; - public JdbcTemplateConfigurationInitializer(JdbcProperties jdbcProperties) { - this.jdbcProperties = jdbcProperties; - } + public JdbcTemplateConfigurationInitializer(JdbcProperties jdbcProperties) { + this.jdbcProperties = jdbcProperties; + } - @Override - public void initialize(GenericApplicationContext context) { - if (context.getBeanFactory().getBeanNamesForType(JdbcTemplateConfiguration.class).length == 0) { - context.registerBean("JdbcTemplate", JdbcTemplate.class, () -> new JdbcTemplateConfiguration().jdbcTemplate(context.getBean(DataSource.class), jdbcProperties)); + @Override + public void initialize(GenericApplicationContext context) { + if ( + context + .getBeanFactory() + .getBeanNamesForType(JdbcTemplateConfiguration.class).length == 0 + ) { + context.registerBean( + "JdbcTemplate", + JdbcTemplate.class, + () -> new JdbcTemplateConfiguration() + .jdbcTemplate( + context.getBean(DataSource.class), + jdbcProperties + ) + ); + } } - } } diff --git a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfigurationInitializer.java b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfigurationInitializer.java index 59d4080dd..2d4d74d9d 100644 --- a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfigurationInitializer.java +++ b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfigurationInitializer.java @@ -1,17 +1,31 @@ package org.springframework.boot.autoconfigure.jdbc.metadata; import java.lang.Override; + import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; public class DataSourcePoolMetadataProvidersConfigurationInitializer implements ApplicationContextInitializer { - @Override - public void initialize(GenericApplicationContext context) { - if (context.getBeanFactory().getBeanNamesForType(DataSourcePoolMetadataProvidersConfiguration.class).length==0) { - context.registerBean(DataSourcePoolMetadataProvidersConfiguration.class, () -> new DataSourcePoolMetadataProvidersConfiguration()); - new DataSourcePoolMetadataProvidersConfiguration_TomcatDataSourcePoolMetadataProviderConfigurationInitializer().initialize(context); - new DataSourcePoolMetadataProvidersConfiguration_HikariPoolDataSourceMetadataProviderConfigurationInitializer().initialize(context); - new DataSourcePoolMetadataProvidersConfiguration_CommonsDbcp2PoolDataSourceMetadataProviderConfigurationInitializer().initialize(context); + @Override + public void initialize(GenericApplicationContext context) { + if ( + context + .getBeanFactory() + .getBeanNamesForType(DataSourcePoolMetadataProvidersConfiguration.class).length == 0 + ) { + context.registerBean( + DataSourcePoolMetadataProvidersConfiguration.class, + DataSourcePoolMetadataProvidersConfiguration::new + ); + + new DataSourcePoolMetadataProvidersConfiguration_TomcatDataSourcePoolMetadataProviderConfigurationInitializer() + .initialize(context); + + new DataSourcePoolMetadataProvidersConfiguration_HikariPoolDataSourceMetadataProviderConfigurationInitializer() + .initialize(context); + + new DataSourcePoolMetadataProvidersConfiguration_CommonsDbcp2PoolDataSourceMetadataProviderConfigurationInitializer() + .initialize(context); + } } - } } diff --git a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_CommonsDbcp2PoolDataSourceMetadataProviderConfigurationInitializer.java b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_CommonsDbcp2PoolDataSourceMetadataProviderConfigurationInitializer.java index 32e9c8043..f01e0e77d 100644 --- a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_CommonsDbcp2PoolDataSourceMetadataProviderConfigurationInitializer.java +++ b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_CommonsDbcp2PoolDataSourceMetadataProviderConfigurationInitializer.java @@ -1,26 +1,44 @@ package org.springframework.boot.autoconfigure.jdbc.metadata; import java.lang.Override; + import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; import org.springframework.util.ClassUtils; public class DataSourcePoolMetadataProvidersConfiguration_CommonsDbcp2PoolDataSourceMetadataProviderConfigurationInitializer implements ApplicationContextInitializer { - private static final boolean enabled; + private static final boolean enabled; + + static { + enabled = + ClassUtils.isPresent( + "org.apache.commons.dbcp2.BasicDataSource", + null + ); + } - static { - enabled = - ClassUtils.isPresent("org.apache.commons.dbcp2.BasicDataSource", null); - } + @Override + public void initialize(GenericApplicationContext context) { + if (DataSourcePoolMetadataProvidersConfiguration_CommonsDbcp2PoolDataSourceMetadataProviderConfigurationInitializer.enabled) { + if ( + context + .getBeanFactory() + .getBeanNamesForType(DataSourcePoolMetadataProvidersConfiguration.CommonsDbcp2PoolDataSourceMetadataProviderConfiguration.class).length == 0 + ) { + context.registerBean( + DataSourcePoolMetadataProvidersConfiguration.CommonsDbcp2PoolDataSourceMetadataProviderConfiguration.class, + DataSourcePoolMetadataProvidersConfiguration.CommonsDbcp2PoolDataSourceMetadataProviderConfiguration::new + ); - @Override - public void initialize(GenericApplicationContext context) { - if (DataSourcePoolMetadataProvidersConfiguration_CommonsDbcp2PoolDataSourceMetadataProviderConfigurationInitializer.enabled) { - if (context.getBeanFactory().getBeanNamesForType(DataSourcePoolMetadataProvidersConfiguration.CommonsDbcp2PoolDataSourceMetadataProviderConfiguration.class).length==0) { - context.registerBean(DataSourcePoolMetadataProvidersConfiguration.CommonsDbcp2PoolDataSourceMetadataProviderConfiguration.class, () -> new DataSourcePoolMetadataProvidersConfiguration.CommonsDbcp2PoolDataSourceMetadataProviderConfiguration()); - context.registerBean("commonsDbcp2PoolDataSourceMetadataProvider", DataSourcePoolMetadataProvider.class, () -> context.getBean(DataSourcePoolMetadataProvidersConfiguration.CommonsDbcp2PoolDataSourceMetadataProviderConfiguration.class).commonsDbcp2PoolDataSourceMetadataProvider()); - } + context.registerBean( + "commonsDbcp2PoolDataSourceMetadataProvider", + DataSourcePoolMetadataProvider.class, + () -> context + .getBean(DataSourcePoolMetadataProvidersConfiguration.CommonsDbcp2PoolDataSourceMetadataProviderConfiguration.class) + .commonsDbcp2PoolDataSourceMetadataProvider() + ); + } + } } - } } diff --git a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_HikariPoolDataSourceMetadataProviderConfigurationInitializer.java b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_HikariPoolDataSourceMetadataProviderConfigurationInitializer.java index 48aefdf8c..d849c3e86 100644 --- a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_HikariPoolDataSourceMetadataProviderConfigurationInitializer.java +++ b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_HikariPoolDataSourceMetadataProviderConfigurationInitializer.java @@ -1,26 +1,44 @@ package org.springframework.boot.autoconfigure.jdbc.metadata; import java.lang.Override; + import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; import org.springframework.util.ClassUtils; public class DataSourcePoolMetadataProvidersConfiguration_HikariPoolDataSourceMetadataProviderConfigurationInitializer implements ApplicationContextInitializer { - private static final boolean enabled; + private static final boolean enabled; + + static { + enabled = + ClassUtils.isPresent( + "com.zaxxer.hikari.HikariDataSource", + null + ); + } - static { - enabled = - ClassUtils.isPresent("com.zaxxer.hikari.HikariDataSource", null); - } + @Override + public void initialize(GenericApplicationContext context) { + if (DataSourcePoolMetadataProvidersConfiguration_HikariPoolDataSourceMetadataProviderConfigurationInitializer.enabled) { + if ( + context + .getBeanFactory() + .getBeanNamesForType(DataSourcePoolMetadataProvidersConfiguration.HikariPoolDataSourceMetadataProviderConfiguration.class).length == 0 + ) { + context.registerBean( + DataSourcePoolMetadataProvidersConfiguration.HikariPoolDataSourceMetadataProviderConfiguration.class, + DataSourcePoolMetadataProvidersConfiguration.HikariPoolDataSourceMetadataProviderConfiguration::new + ); - @Override - public void initialize(GenericApplicationContext context) { - if (DataSourcePoolMetadataProvidersConfiguration_HikariPoolDataSourceMetadataProviderConfigurationInitializer.enabled) { - if (context.getBeanFactory().getBeanNamesForType(DataSourcePoolMetadataProvidersConfiguration.HikariPoolDataSourceMetadataProviderConfiguration.class).length==0) { - context.registerBean(DataSourcePoolMetadataProvidersConfiguration.HikariPoolDataSourceMetadataProviderConfiguration.class, () -> new DataSourcePoolMetadataProvidersConfiguration.HikariPoolDataSourceMetadataProviderConfiguration()); - context.registerBean("hikariPoolDataSourceMetadataProvider", DataSourcePoolMetadataProvider.class, () -> context.getBean(DataSourcePoolMetadataProvidersConfiguration.HikariPoolDataSourceMetadataProviderConfiguration.class).hikariPoolDataSourceMetadataProvider()); - } + context.registerBean( + "hikariPoolDataSourceMetadataProvider", + DataSourcePoolMetadataProvider.class, + () -> context + .getBean(DataSourcePoolMetadataProvidersConfiguration.HikariPoolDataSourceMetadataProviderConfiguration.class) + .hikariPoolDataSourceMetadataProvider() + ); + } + } } - } } diff --git a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_TomcatDataSourcePoolMetadataProviderConfigurationInitializer.java b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_TomcatDataSourcePoolMetadataProviderConfigurationInitializer.java index df56003c5..665d25813 100644 --- a/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_TomcatDataSourcePoolMetadataProviderConfigurationInitializer.java +++ b/autoconfigure-adapter-jdbc/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration_TomcatDataSourcePoolMetadataProviderConfigurationInitializer.java @@ -1,26 +1,44 @@ package org.springframework.boot.autoconfigure.jdbc.metadata; import java.lang.Override; + import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; import org.springframework.util.ClassUtils; public class DataSourcePoolMetadataProvidersConfiguration_TomcatDataSourcePoolMetadataProviderConfigurationInitializer implements ApplicationContextInitializer { - private static final boolean enabled; + private static final boolean enabled; + + static { + enabled = + ClassUtils.isPresent( + "org.apache.tomcat.jdbc.pool.DataSource", + null + ); + } - static { - enabled = - ClassUtils.isPresent("org.apache.tomcat.jdbc.pool.DataSource", null); - } + @Override + public void initialize(GenericApplicationContext context) { + if (DataSourcePoolMetadataProvidersConfiguration_TomcatDataSourcePoolMetadataProviderConfigurationInitializer.enabled) { + if ( + context + .getBeanFactory() + .getBeanNamesForType(DataSourcePoolMetadataProvidersConfiguration.TomcatDataSourcePoolMetadataProviderConfiguration.class).length == 0 + ) { + context.registerBean( + DataSourcePoolMetadataProvidersConfiguration.TomcatDataSourcePoolMetadataProviderConfiguration.class, + DataSourcePoolMetadataProvidersConfiguration.TomcatDataSourcePoolMetadataProviderConfiguration::new + ); - @Override - public void initialize(GenericApplicationContext context) { - if (DataSourcePoolMetadataProvidersConfiguration_TomcatDataSourcePoolMetadataProviderConfigurationInitializer.enabled) { - if (context.getBeanFactory().getBeanNamesForType(DataSourcePoolMetadataProvidersConfiguration.TomcatDataSourcePoolMetadataProviderConfiguration.class).length==0) { - context.registerBean(DataSourcePoolMetadataProvidersConfiguration.TomcatDataSourcePoolMetadataProviderConfiguration.class, () -> new DataSourcePoolMetadataProvidersConfiguration.TomcatDataSourcePoolMetadataProviderConfiguration()); - context.registerBean("tomcatPoolDataSourceMetadataProvider", DataSourcePoolMetadataProvider.class, () -> context.getBean(DataSourcePoolMetadataProvidersConfiguration.TomcatDataSourcePoolMetadataProviderConfiguration.class).tomcatPoolDataSourceMetadataProvider()); - } + context.registerBean( + "tomcatPoolDataSourceMetadataProvider", + DataSourcePoolMetadataProvider.class, + () -> context + .getBean(DataSourcePoolMetadataProvidersConfiguration.TomcatDataSourcePoolMetadataProviderConfiguration.class) + .tomcatPoolDataSourceMetadataProvider() + ); + } + } } - } } diff --git a/autoconfigure-adapter-jooq/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqConfigurationInitializer.java b/autoconfigure-adapter-jooq/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqConfigurationInitializer.java index 89d329037..6aa698e59 100644 --- a/autoconfigure-adapter-jooq/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqConfigurationInitializer.java +++ b/autoconfigure-adapter-jooq/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqConfigurationInitializer.java @@ -12,7 +12,7 @@ /** * @author Kevin Davin */ -public class JooqConfigurationInitializer implements ApplicationContextInitializer { +public class JooqConfigurationInitializer implements ApplicationContextInitializer { private final JooqProperties jooqProperties; @@ -22,22 +22,39 @@ public JooqConfigurationInitializer(JooqProperties jooqProperties) { @Override public void initialize(GenericApplicationContext context) { - if (context.getBeanFactory().getBeanNamesForType(DSLContext.class).length != 0) { + if (context + .getBeanFactory() + .getBeanNamesForType(DSLContext.class).length != 0) { return; } - context.registerBean(DataSourceConnectionProvider.class, () -> new JooqAutoConfiguration().dataSourceConnectionProvider(context.getBean(DataSource.class))); - context.registerBean(DefaultExecuteListenerProvider.class, () -> new JooqAutoConfiguration().jooqExceptionTranslatorExecuteListenerProvider()); - context.registerBean(DefaultConfiguration.class, - () -> new JooqAutoConfiguration.DslContextConfiguration().jooqConfiguration( - jooqProperties, - context.getBean(ConnectionProvider.class), - context.getBean(DataSource.class), - context.getBeanProvider(ExecuteListenerProvider.class), - context.getBeanProvider(DefaultConfigurationCustomizer.class) + context.registerBean( + DataSourceConnectionProvider.class, + () -> new JooqAutoConfiguration().dataSourceConnectionProvider(context.getBean(DataSource.class)) + ); + + context.registerBean( + DefaultExecuteListenerProvider.class, + () -> new JooqAutoConfiguration().jooqExceptionTranslatorExecuteListenerProvider() + ); + + context.registerBean( + DefaultConfiguration.class, + () -> new JooqAutoConfiguration.DslContextConfiguration() + .jooqConfiguration( + jooqProperties, + context.getBean(ConnectionProvider.class), + context.getBean(DataSource.class), + context.getBeanProvider(TransactionProvider.class), + context.getBeanProvider(ExecuteListenerProvider.class), + context.getBeanProvider(DefaultConfigurationCustomizer.class) ) ); - context.registerBean("dslContext", DSLContext.class, () -> new JooqAutoConfiguration.DslContextConfiguration().dslContext(context.getBean(Configuration.class))); + context.registerBean( + "dslContext", + DSLContext.class, + () -> new JooqAutoConfiguration.DslContextConfiguration().dslContext(context.getBean(Configuration.class)) + ); } } diff --git a/autoconfigure-adapter-mongo/build.gradle.kts b/autoconfigure-adapter-mongo/build.gradle.kts index 1e2d300b2..442948068 100644 --- a/autoconfigure-adapter-mongo/build.gradle.kts +++ b/autoconfigure-adapter-mongo/build.gradle.kts @@ -7,7 +7,6 @@ dependencies { api("org.springframework.boot:spring-boot") api("org.springframework.boot:spring-boot-autoconfigure") - compileOnly("de.flapdoodle.embed:de.flapdoodle.embed.mongo.spring30x:4.7.0") compileOnly("org.mongodb:mongodb-driver-legacy") compileOnly("org.mongodb:mongodb-driver-reactivestreams") compileOnly("org.springframework.data:spring-data-mongodb") diff --git a/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataInitializer.java b/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataInitializer.java index 95f193f35..d26ce12d4 100644 --- a/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataInitializer.java +++ b/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataInitializer.java @@ -42,21 +42,57 @@ public MongoDataInitializer(MongoProperties properties) { @Override public void initialize(GenericApplicationContext context) { MongoDataConfiguration dataConfiguration = new MongoDataConfiguration(); - context.registerBean(MongoCustomConversions.class, dataConfiguration::mongoCustomConversions); - context.registerBean(MongoMappingContext.class, () -> { - try { - return dataConfiguration.mongoMappingContext(context, properties, context.getBean(MongoCustomConversions.class)); - } catch (ClassNotFoundException e) { - e.printStackTrace(); + context.registerBean( + MongoCustomConversions.class, + dataConfiguration::mongoCustomConversions + ); + + context.registerBean( + MongoMappingContext.class, + () -> { + try { + return dataConfiguration.mongoMappingContext( + properties, + context.getBean(MongoCustomConversions.class), + MongoDataConfiguration.mongoManagedTypes(context) + ); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + return null; } - return null; - }); - context.registerBean(MongoCustomConversions.class, dataConfiguration::mongoCustomConversions); - - MongoDatabaseFactoryDependentConfiguration conf = new MongoDatabaseFactoryDependentConfiguration(properties); - context.registerBean(SimpleMongoClientDatabaseFactory.class, () -> new SimpleMongoClientDatabaseFactory(context.getBean(MongoClient.class), properties.getMongoClientDatabase())); - context.registerBean(MongoConverter.class, () -> conf.mappingMongoConverter(context.getBean(MongoDatabaseFactory.class), context.getBean(MongoMappingContext.class), context.getBean(MongoCustomConversions.class))); - context.registerBean(MongoTemplate.class, () -> conf.mongoTemplate(context.getBean(MongoDatabaseFactory.class), context.getBean(MongoConverter.class))); + ); + + context.registerBean( + MongoCustomConversions.class, + dataConfiguration::mongoCustomConversions + ); + + MongoDatabaseFactoryDependentConfiguration conf = new MongoDatabaseFactoryDependentConfiguration(); + context.registerBean( + SimpleMongoClientDatabaseFactory.class, + () -> new SimpleMongoClientDatabaseFactory( + context.getBean(MongoClient.class), + properties.getMongoClientDatabase() + ) + ); + + context.registerBean( + MongoConverter.class, + () -> conf.mappingMongoConverter( + context.getBean(MongoDatabaseFactory.class), + context.getBean(MongoMappingContext.class), + context.getBean(MongoCustomConversions.class) + ) + ); + + context.registerBean( + MongoTemplate.class, + () -> conf.mongoTemplate( + context.getBean(MongoDatabaseFactory.class), + context.getBean(MongoConverter.class) + ) + ); } } diff --git a/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataInitializer.java b/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataInitializer.java index a2317999c..8c2b33b51 100644 --- a/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataInitializer.java +++ b/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataInitializer.java @@ -18,6 +18,7 @@ import com.mongodb.reactivestreams.client.MongoClient; import org.springframework.boot.autoconfigure.mongo.MongoProperties; +import org.springframework.boot.autoconfigure.mongo.PropertiesMongoConnectionDetails; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; import org.springframework.data.mongodb.ReactiveMongoDatabaseFactory; @@ -42,27 +43,64 @@ public MongoReactiveDataInitializer(MongoProperties properties) { @Override public void initialize(GenericApplicationContext context) { MongoDataConfiguration dataConfiguration = new MongoDataConfiguration(); - if (context.getBeanFactory().getBeanNamesForType(MongoCustomConversions.class).length == 0) { - context.registerBean(MongoCustomConversions.class, dataConfiguration::mongoCustomConversions); + if ( + context + .getBeanFactory() + .getBeanNamesForType(MongoCustomConversions.class).length == 0 + ) { + context.registerBean( + MongoCustomConversions.class, + dataConfiguration::mongoCustomConversions + ); } - if (context.getBeanFactory().getBeanNamesForType(MongoMappingContext.class).length == 0) { - context.registerBean(MongoMappingContext.class, () -> { - try { - return dataConfiguration.mongoMappingContext( - context, - properties, - context.getBean(MongoCustomConversions.class) - ); - } catch (ClassNotFoundException e) { - e.printStackTrace(); + + if ( + context + .getBeanFactory() + .getBeanNamesForType(MongoMappingContext.class).length == 0 + ) { + context.registerBean( + MongoMappingContext.class, + () -> { + try { + return dataConfiguration.mongoMappingContext( + properties, + context.getBean(MongoCustomConversions.class), + MongoDataConfiguration.mongoManagedTypes(context) + ); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + return null; } - return null; - }); + ); } - MongoReactiveDataAutoConfiguration configuration = new MongoReactiveDataAutoConfiguration(); - context.registerBean(MappingMongoConverter.class, () -> configuration.mappingMongoConverter(context.getBean(MongoMappingContext.class), context.getBean(MongoCustomConversions.class))); - context.registerBean(SimpleReactiveMongoDatabaseFactory.class, () -> configuration.reactiveMongoDatabaseFactory(this.properties, context.getBean(MongoClient.class))); - context.registerBean(ReactiveMongoTemplate.class, () -> configuration.reactiveMongoTemplate(context.getBean(ReactiveMongoDatabaseFactory.class), context.getBean(MongoConverter.class))); + MongoReactiveDataAutoConfiguration configuration = new MongoReactiveDataAutoConfiguration( + new PropertiesMongoConnectionDetails(properties) + ); + context.registerBean( + MappingMongoConverter.class, + () -> configuration.mappingMongoConverter( + context.getBean(MongoMappingContext.class), + context.getBean(MongoCustomConversions.class) + ) + ); + + context.registerBean( + SimpleReactiveMongoDatabaseFactory.class, + () -> configuration.reactiveMongoDatabaseFactory( + context.getBean(MongoClient.class), + this.properties + ) + ); + + context.registerBean( + ReactiveMongoTemplate.class, + () -> configuration.reactiveMongoTemplate( + context.getBean(ReactiveMongoDatabaseFactory.class), + context.getBean(MongoConverter.class) + ) + ); } } diff --git a/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoInitializer.java b/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoInitializer.java index 1c1f2377c..3ae0cb503 100644 --- a/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoInitializer.java +++ b/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoInitializer.java @@ -20,6 +20,7 @@ import com.mongodb.client.MongoClient; import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; +import org.springframework.boot.ssl.SslBundles; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; @@ -28,24 +29,38 @@ */ public class MongoInitializer implements ApplicationContextInitializer { - private final MongoProperties properties; - - private final boolean embeddedServer; - - public MongoInitializer(MongoProperties properties, boolean embeddedServer) { - this.properties = properties; - this.embeddedServer = embeddedServer; - } - - @Override - public void initialize(GenericApplicationContext context) { - MongoAutoConfiguration configuration = new MongoAutoConfiguration(); - MongoAutoConfiguration.MongoClientSettingsConfiguration mongoClientSettingsConfiguration = new MongoAutoConfiguration.MongoClientSettingsConfiguration(); - context.registerBean(MongoClientSettingsBuilderCustomizer.class, () -> mongoClientSettingsConfiguration.mongoPropertiesCustomizer(this.properties, context.getEnvironment())); - context.registerBean(MongoClient.class, () -> configuration.mongo(context.getBeanProvider(MongoClientSettingsBuilderCustomizer.class), mongoClientSettingsConfiguration.mongoClientSettings()), (definition) -> { - if (embeddedServer) { - definition.setDependsOn("embeddedMongoServer"); - } - }); - } + private final MongoProperties properties; + + private final boolean embeddedServer; + + public MongoInitializer( + MongoProperties properties, + boolean embeddedServer + ) { + this.properties = properties; + this.embeddedServer = embeddedServer; + } + + @Override + public void initialize(GenericApplicationContext context) { + MongoAutoConfiguration configuration = new MongoAutoConfiguration(); + MongoAutoConfiguration.MongoClientSettingsConfiguration mongoClientSettingsConfiguration = new MongoAutoConfiguration.MongoClientSettingsConfiguration(); + + context.registerBean( + MongoClientSettingsBuilderCustomizer.class, + () -> mongoClientSettingsConfiguration.standardMongoSettingsCustomizer( + this.properties, + configuration.mongoConnectionDetails(properties), + context.getBeanProvider(SslBundles.class) + ) + ); + + context.registerBean( + MongoClient.class, + () -> configuration.mongo( + context.getBeanProvider(MongoClientSettingsBuilderCustomizer.class), + mongoClientSettingsConfiguration.mongoClientSettings() + ) + ); + } } diff --git a/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveInitializer.java b/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveInitializer.java index dfb0c2de7..0f0f8666a 100644 --- a/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveInitializer.java +++ b/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveInitializer.java @@ -19,33 +19,57 @@ import com.mongodb.MongoClientSettings; import com.mongodb.reactivestreams.client.MongoClient; +import org.springframework.boot.ssl.SslBundles; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; /** -* {@link ApplicationContextInitializer} adapter for {@link MongoReactiveAutoConfiguration}. -*/ + * {@link ApplicationContextInitializer} adapter for {@link MongoReactiveAutoConfiguration}. + */ public class MongoReactiveInitializer implements ApplicationContextInitializer { - private final MongoProperties properties; - - private final boolean embeddedServer; - - public MongoReactiveInitializer(MongoProperties properties, boolean embeddedServer) { - this.properties = properties; - this.embeddedServer = embeddedServer; - } - - @Override - public void initialize(GenericApplicationContext context) { - context.registerBean(MongoClientSettingsBuilderCustomizer.class, () -> new MongoReactiveAutoConfiguration.NettyDriverConfiguration().nettyDriverCustomizer(context.getDefaultListableBeanFactory().getBeanProvider(MongoClientSettings.class))); - context.registerBean(MongoClient.class, () -> new MongoReactiveAutoConfiguration().reactiveStreamsMongoClient(context.getBeanProvider(MongoClientSettingsBuilderCustomizer.class), context.getBean(MongoClientSettings.class)), (definition) -> { - if (embeddedServer) { - definition.setDependsOn("embeddedMongoServer"); - } - }); - MongoReactiveAutoConfiguration.MongoClientSettingsConfiguration configuration = new MongoReactiveAutoConfiguration.MongoClientSettingsConfiguration(); - context.registerBean(MongoClientSettings.class, () -> configuration.mongoClientSettings()); - context.registerBean(MongoPropertiesClientSettingsBuilderCustomizer.class, () -> configuration.mongoPropertiesCustomizer(properties, context.getEnvironment())); - } + private final MongoProperties properties; + + public MongoReactiveInitializer( + MongoProperties properties + ) { + this.properties = properties; + } + + @Override + public void initialize(GenericApplicationContext context) { + context.registerBean( + MongoClientSettingsBuilderCustomizer.class, + () -> new MongoReactiveAutoConfiguration.NettyDriverConfiguration() + .nettyDriverCustomizer( + context + .getDefaultListableBeanFactory() + .getBeanProvider(MongoClientSettings.class) + ) + ); + + MongoReactiveAutoConfiguration configuration = new MongoReactiveAutoConfiguration(); + context.registerBean( + MongoClient.class, + () -> configuration.reactiveStreamsMongoClient( + context.getBeanProvider(MongoClientSettingsBuilderCustomizer.class), + context.getBean(MongoClientSettings.class) + ) + ); + + MongoReactiveAutoConfiguration.MongoClientSettingsConfiguration mongoClientSettingsConfiguration = new MongoReactiveAutoConfiguration.MongoClientSettingsConfiguration(); + context.registerBean( + MongoClientSettings.class, + mongoClientSettingsConfiguration::mongoClientSettings + ); + + context.registerBean( + MongoClientSettingsBuilderCustomizer.class, + () -> mongoClientSettingsConfiguration.standardMongoSettingsCustomizer( + this.properties, + configuration.mongoConnectionDetails(properties), + context.getBeanProvider(SslBundles.class) + ) + ); + } } diff --git a/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoInitializer.java b/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoInitializer.java deleted file mode 100644 index 85076f4dc..000000000 --- a/autoconfigure-adapter-mongo/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoInitializer.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2002-2018 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.autoconfigure.mongo.embedded; - -import java.io.IOException; - -import de.flapdoodle.embed.mongo.MongodExecutable; - -import de.flapdoodle.embed.mongo.config.MongodConfig; -import de.flapdoodle.embed.process.config.RuntimeConfig; -import org.springframework.boot.autoconfigure.mongo.MongoProperties; -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.support.GenericApplicationContext; - -public class EmbeddedMongoInitializer implements ApplicationContextInitializer { - - private final MongoProperties properties; - - private final EmbeddedMongoProperties embeddedProperties; - - public EmbeddedMongoInitializer(MongoProperties mongoProperties, EmbeddedMongoProperties embeddedProperties) { - this.properties = mongoProperties; - this.embeddedProperties = embeddedProperties; - } - - @Override - public void initialize(GenericApplicationContext context) { - EmbeddedMongoAutoConfiguration configuration = new EmbeddedMongoAutoConfiguration(this.properties); - context.registerBean(MongodConfig.class, () -> { - try { - return configuration.embeddedMongoConfiguration(this.embeddedProperties); - } - catch (IOException e) { - e.printStackTrace(); - } - return null; - }); - context.registerBean("embeddedMongoServer", MongodExecutable.class, () -> - configuration.embeddedMongoServer(context.getBean(MongodConfig.class), context.getBean(RuntimeConfig.class), context), definition -> { - definition.setInitMethodName("start"); - definition.setDestroyMethodName("stop"); - }); - context.registerBean(RuntimeConfig.class, () -> new EmbeddedMongoAutoConfiguration.RuntimeConfigConfiguration().embeddedMongoRuntimeConfig(context.getBeanProvider(DownloadConfigBuilderCustomizer.class))); - } -} diff --git a/autoconfigure-adapter-mustache/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheInitializer.java b/autoconfigure-adapter-mustache/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheInitializer.java index 99b5abb7d..b04a5b6e9 100644 --- a/autoconfigure-adapter-mustache/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheInitializer.java +++ b/autoconfigure-adapter-mustache/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheInitializer.java @@ -26,16 +26,29 @@ */ public class MustacheInitializer implements ApplicationContextInitializer { - private final MustacheProperties properties; - - public MustacheInitializer(MustacheProperties properties) { - this.properties = properties; - } - - @Override - public void initialize(GenericApplicationContext context) { - MustacheAutoConfiguration configuration = new MustacheAutoConfiguration(this.properties, context); - context.registerBean(MustacheResourceTemplateLoader.class, configuration::mustacheTemplateLoader); - context.registerBean(Mustache.Compiler.class, () -> configuration.mustacheCompiler(context.getBean(Mustache.TemplateLoader.class), context.getEnvironment())); - } + private final MustacheProperties properties; + + public MustacheInitializer(MustacheProperties properties) { + this.properties = properties; + } + + @Override + public void initialize(GenericApplicationContext context) { + MustacheAutoConfiguration configuration = new MustacheAutoConfiguration( + this.properties, + context + ); + + context.registerBean( + MustacheResourceTemplateLoader.class, + configuration::mustacheTemplateLoader + ); + + context.registerBean( + Mustache.Compiler.class, + () -> configuration.mustacheCompiler( + context.getBean(Mustache.TemplateLoader.class) + ) + ); + } } diff --git a/autoconfigure-adapter-mustache/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebInitializer.java b/autoconfigure-adapter-mustache/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebInitializer.java index cda82714a..db4225460 100644 --- a/autoconfigure-adapter-mustache/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebInitializer.java +++ b/autoconfigure-adapter-mustache/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebInitializer.java @@ -27,15 +27,22 @@ */ public class MustacheReactiveWebInitializer implements ApplicationContextInitializer { - private final MustacheProperties properties; + private final MustacheProperties properties; - public MustacheReactiveWebInitializer(MustacheProperties properties) { - this.properties = properties; - } + public MustacheReactiveWebInitializer(MustacheProperties properties) { + this.properties = properties; + } - @Override - public void initialize(GenericApplicationContext context) { - MustacheReactiveWebConfiguration configuration = new MustacheReactiveWebConfiguration(); - context.registerBean(ViewResolver.class, () -> configuration.mustacheViewResolver(context.getBean(Mustache.Compiler.class), this.properties)); - } + @Override + public void initialize(GenericApplicationContext context) { + MustacheReactiveWebConfiguration configuration = new MustacheReactiveWebConfiguration(); + + context.registerBean( + ViewResolver.class, + () -> configuration.mustacheViewResolver( + context.getBean(Mustache.Compiler.class), + this.properties + ) + ); + } } diff --git a/autoconfigure-adapter-mustache/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebInitializer.java b/autoconfigure-adapter-mustache/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebInitializer.java index 617a11c31..4838073ff 100644 --- a/autoconfigure-adapter-mustache/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebInitializer.java +++ b/autoconfigure-adapter-mustache/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebInitializer.java @@ -27,15 +27,22 @@ */ public class MustacheServletWebInitializer implements ApplicationContextInitializer { - private final MustacheProperties properties; + private final MustacheProperties properties; - public MustacheServletWebInitializer(MustacheProperties properties) { - this.properties = properties; - } + public MustacheServletWebInitializer(MustacheProperties properties) { + this.properties = properties; + } - @Override - public void initialize(GenericApplicationContext context) { - MustacheServletWebConfiguration configuration = new MustacheServletWebConfiguration(); - context.registerBean("mustacheViewResolver", ViewResolver.class, () -> configuration.mustacheViewResolver(context.getBean(Mustache.Compiler.class), this.properties)); - } + @Override + public void initialize(GenericApplicationContext context) { + MustacheServletWebConfiguration configuration = new MustacheServletWebConfiguration(); + context.registerBean( + "mustacheViewResolver", + ViewResolver.class, + () -> configuration.mustacheViewResolver( + context.getBean(Mustache.Compiler.class), + this.properties + ) + ); + } } diff --git a/autoconfigure-adapter-r2dbc/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataInitializer.java b/autoconfigure-adapter-r2dbc/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataInitializer.java index 264ab3ab9..e1d0eb147 100644 --- a/autoconfigure-adapter-r2dbc/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataInitializer.java +++ b/autoconfigure-adapter-r2dbc/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataInitializer.java @@ -7,6 +7,7 @@ import org.springframework.data.r2dbc.convert.R2dbcCustomConversions; import org.springframework.data.r2dbc.core.R2dbcEntityTemplate; import org.springframework.data.r2dbc.mapping.R2dbcMappingContext; +import org.springframework.data.relational.RelationalManagedTypes; import org.springframework.data.relational.core.mapping.NamingStrategy; import org.springframework.r2dbc.core.DatabaseClient; @@ -19,7 +20,7 @@ public R2dbcDataInitializer() { @Override public void initialize(GenericApplicationContext context) { - Supplier r2dbcDataConfiguration = new Supplier() { + Supplier r2dbcDataConfiguration = new Supplier<>() { private R2dbcDataAutoConfiguration configuration; @@ -32,9 +33,50 @@ public R2dbcDataAutoConfiguration get() { } }; - context.registerBean(R2dbcEntityTemplate.class, () -> r2dbcDataConfiguration.get().r2dbcEntityTemplate(context.getBean(R2dbcConverter.class))); - context.registerBean(R2dbcCustomConversions.class, () -> r2dbcDataConfiguration.get().r2dbcCustomConversions()); - context.registerBean(R2dbcMappingContext.class, () -> r2dbcDataConfiguration.get().r2dbcMappingContext(context.getBeanProvider(NamingStrategy.class), context.getBean(R2dbcCustomConversions.class))); - context.registerBean(MappingR2dbcConverter.class, () -> r2dbcDataConfiguration.get().r2dbcConverter(context.getBean(R2dbcMappingContext.class), context.getBean(R2dbcCustomConversions.class))); + context.registerBean( + R2dbcEntityTemplate.class, + () -> r2dbcDataConfiguration + .get() + .r2dbcEntityTemplate(context.getBean(R2dbcConverter.class)) + ); + + context.registerBean( + R2dbcCustomConversions.class, + () -> r2dbcDataConfiguration + .get() + .r2dbcCustomConversions() + ); + + context.registerBean( + RelationalManagedTypes.class, + () -> { + try { + return R2dbcDataAutoConfiguration.r2dbcManagedTypes(context); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + ); + + context.registerBean( + R2dbcMappingContext.class, + () -> r2dbcDataConfiguration + .get() + .r2dbcMappingContext( + context.getBeanProvider(NamingStrategy.class), + context.getBean(R2dbcCustomConversions.class), + context.getBean(RelationalManagedTypes.class) + ) + ); + + context.registerBean( + MappingR2dbcConverter.class, + () -> r2dbcDataConfiguration + .get() + .r2dbcConverter( + context.getBean(R2dbcMappingContext.class), + context.getBean(R2dbcCustomConversions.class) + ) + ); } } diff --git a/autoconfigure-adapter-r2dbc/src/main/java/org/springframework/boot/autoconfigure/r2dbc/R2dbcInitializer.java b/autoconfigure-adapter-r2dbc/src/main/java/org/springframework/boot/autoconfigure/r2dbc/R2dbcInitializer.java index 8b187bf15..eafd0a2a6 100644 --- a/autoconfigure-adapter-r2dbc/src/main/java/org/springframework/boot/autoconfigure/r2dbc/R2dbcInitializer.java +++ b/autoconfigure-adapter-r2dbc/src/main/java/org/springframework/boot/autoconfigure/r2dbc/R2dbcInitializer.java @@ -1,6 +1,8 @@ package org.springframework.boot.autoconfigure.r2dbc; import io.r2dbc.spi.ConnectionFactory; +import org.springframework.boot.r2dbc.ConnectionFactoryBuilder; +import org.springframework.boot.r2dbc.EmbeddedDatabaseConnection; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; import org.springframework.r2dbc.connection.R2dbcTransactionManager; @@ -11,32 +13,59 @@ import java.util.List; public class R2dbcInitializer implements ApplicationContextInitializer { - private final R2dbcProperties properties; - private final List optionsCustomizers; - private final boolean transactional; - - public R2dbcInitializer(R2dbcProperties properties, List optionsCustomizers, boolean transactional) { - this.properties = properties; - this.optionsCustomizers = optionsCustomizers; - this.transactional = transactional; - } - - @Override - public void initialize(GenericApplicationContext context) { - ConnectionFactory connectionFactory = ConnectionFactoryBuilder.of(properties, () -> EmbeddedDatabaseConnection.get(context.getClassLoader())) - .configure((options) -> { - for (ConnectionFactoryOptionsBuilderCustomizer optionsCustomizer : optionsCustomizers) { - optionsCustomizer.customize(options); - } - }) - .build(); - - context.registerBean(ConnectionFactory.class, () -> connectionFactory); - context.registerBean(DatabaseClient.class, () -> DatabaseClient.builder().connectionFactory(connectionFactory).build()); - - if (transactional) { - ReactiveTransactionManager reactiveTransactionManager = new R2dbcTransactionManager(connectionFactory); - context.registerBean(TransactionalOperator.class, () -> TransactionalOperator.create(reactiveTransactionManager)); - } - } + private final R2dbcProperties properties; + private final List optionsCustomizers; + private final boolean transactional; + + public R2dbcInitializer( + R2dbcProperties properties, + List optionsCustomizers, + boolean transactional + ) { + this.properties = properties; + this.optionsCustomizers = optionsCustomizers; + this.transactional = transactional; + } + + @Override + public void initialize(GenericApplicationContext context) { + ConnectionFactory connectionFactory = ConnectionFactoryBuilder + .withOptions( + new ConnectionFactoryOptionsInitializer() + .initialize( + properties, + context + .getBeanProvider(R2dbcConnectionDetails.class) + .getIfAvailable(), + () -> EmbeddedDatabaseConnection.get(context.getClassLoader()) + ) + ) + .configure((options) -> { + for (ConnectionFactoryOptionsBuilderCustomizer optionsCustomizer : optionsCustomizers) { + optionsCustomizer.customize(options); + } + }) + .build(); + + context.registerBean( + ConnectionFactory.class, + () -> connectionFactory + ); + + context.registerBean( + DatabaseClient.class, + () -> DatabaseClient + .builder() + .connectionFactory(connectionFactory) + .build() + ); + + if (transactional) { + ReactiveTransactionManager reactiveTransactionManager = new R2dbcTransactionManager(connectionFactory); + context.registerBean( + TransactionalOperator.class, + () -> TransactionalOperator.create(reactiveTransactionManager) + ); + } + } } diff --git a/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/ClusterInitializer.java b/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/ClusterInitializer.java index f77241eb1..f3676bb85 100644 --- a/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/ClusterInitializer.java +++ b/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/ClusterInitializer.java @@ -18,7 +18,10 @@ public ClusterInitializer(Cluster cluster) { @Override public void initialize(GenericApplicationContext context) { if (cluster != null) { - context.registerBean(RedisClusterConfiguration.class, this::getRedisClusterConfiguration); + context.registerBean( + RedisClusterConfiguration.class, + this::getRedisClusterConfiguration + ); } } diff --git a/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisRedisInitializer.java b/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisRedisInitializer.java index e4153d03d..539ebca54 100644 --- a/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisRedisInitializer.java +++ b/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisRedisInitializer.java @@ -1,5 +1,6 @@ package org.springframework.boot.autoconfigure.data.redis; +import org.springframework.boot.ssl.SslBundles; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; import org.springframework.data.redis.connection.RedisClusterConfiguration; @@ -20,13 +21,28 @@ public JedisRedisInitializer(RedisProperties redisProperties) { @Override public void initialize(GenericApplicationContext context) { - if (redisProperties.getJedis().getPool() != null) { - context.registerBean(RedisConnectionFactory.class, () -> getJedisConnectionFactory(context)); + if ( + redisProperties + .getJedis() + .getPool() != null + ) { + context.registerBean( + RedisConnectionFactory.class, + () -> getJedisConnectionFactory(context) + ); } } private JedisConnectionFactory getJedisConnectionFactory(GenericApplicationContext context) { - final JedisConnectionConfiguration configuration = new JedisConnectionConfiguration(redisProperties, context.getBeanProvider(RedisStandaloneConfiguration.class), context.getBeanProvider(RedisSentinelConfiguration.class), context.getBeanProvider(RedisClusterConfiguration.class)); + JedisConnectionConfiguration configuration = new JedisConnectionConfiguration( + redisProperties, + context.getBeanProvider(RedisStandaloneConfiguration.class), + context.getBeanProvider(RedisSentinelConfiguration.class), + context.getBeanProvider(RedisClusterConfiguration.class), + new PropertiesRedisConnectionDetails(redisProperties), + context.getBeanProvider(SslBundles.class) + ); + return configuration.redisConnectionFactory(context.getBeanProvider(JedisClientConfigurationBuilderCustomizer.class)); } } diff --git a/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceRedisInitializer.java b/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceRedisInitializer.java index 8cace9453..8106a0f61 100644 --- a/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceRedisInitializer.java +++ b/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceRedisInitializer.java @@ -2,6 +2,7 @@ import io.lettuce.core.resource.ClientResources; import io.lettuce.core.resource.DefaultClientResources; +import org.springframework.boot.ssl.SslBundles; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; import org.springframework.data.redis.connection.RedisClusterConfiguration; @@ -21,12 +22,26 @@ public LettuceRedisInitializer(RedisProperties redisProperties) { @Override public void initialize(GenericApplicationContext context) { - context.registerBean(LettuceConnectionFactory.class, () -> getLettuceConnectionFactory(context)); + context.registerBean( + LettuceConnectionFactory.class, + () -> getLettuceConnectionFactory(context) + ); } private LettuceConnectionFactory getLettuceConnectionFactory(GenericApplicationContext context) { - final LettuceConnectionConfiguration configuration = new LettuceConnectionConfiguration(redisProperties, context.getBeanProvider(RedisStandaloneConfiguration.class), context.getBeanProvider(RedisSentinelConfiguration.class), context.getBeanProvider(RedisClusterConfiguration.class)); - final ClientResources clientResources = DefaultClientResources.create(); - return configuration.redisConnectionFactory(context.getBeanProvider(LettuceClientConfigurationBuilderCustomizer.class), clientResources); + final LettuceConnectionConfiguration configuration = new LettuceConnectionConfiguration( + redisProperties, + context.getBeanProvider(RedisStandaloneConfiguration.class), + context.getBeanProvider(RedisSentinelConfiguration.class), + context.getBeanProvider(RedisClusterConfiguration.class), + new PropertiesRedisConnectionDetails(redisProperties), + context.getBeanProvider(SslBundles.class) + ); + + ClientResources clientResources = DefaultClientResources.create(); + return configuration.redisConnectionFactory( + context.getBeanProvider(LettuceClientConfigurationBuilderCustomizer.class), + clientResources + ); } } diff --git a/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisInitializer.java b/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisInitializer.java index 7cfd3675e..16b76ac9a 100644 --- a/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisInitializer.java +++ b/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisInitializer.java @@ -17,7 +17,20 @@ public class RedisInitializer implements ApplicationContextInitializer redisAutoConfiguration.redisTemplate(context.getBean(RedisConnectionFactory.class)), (definition) -> ((RootBeanDefinition) definition).setTargetType(ResolvableType.forClassWithGenerics(RedisTemplate.class, Object.class, Object.class))); - context.registerBean("stringRedisTemplate", StringRedisTemplate.class, () -> redisAutoConfiguration.stringRedisTemplate(context.getBean(RedisConnectionFactory.class))); + context.registerBean( + "redisTemplate", + RedisTemplate.class, + () -> redisAutoConfiguration.redisTemplate(context.getBean(RedisConnectionFactory.class)), + (definition) -> ((RootBeanDefinition) definition).setTargetType(ResolvableType.forClassWithGenerics(RedisTemplate.class, + Object.class, + Object.class + )) + ); + + context.registerBean( + "stringRedisTemplate", + StringRedisTemplate.class, + () -> redisAutoConfiguration.stringRedisTemplate(context.getBean(RedisConnectionFactory.class)) + ); } } diff --git a/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveInitializer.java b/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveInitializer.java index 7e5754176..070bc809b 100644 --- a/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveInitializer.java +++ b/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveInitializer.java @@ -15,10 +15,22 @@ public class RedisReactiveInitializer implements ApplicationContextInitializer redisAutoConfiguration.reactiveRedisTemplate(context.getBean(ReactiveRedisConnectionFactory.class), context), - (definition) -> ((RootBeanDefinition) definition).setTargetType(ResolvableType.forClassWithGenerics(ReactiveRedisTemplate.class, Object.class, Object.class))); - context.registerBean("reactiveStringRedisTemplate", ReactiveStringRedisTemplate.class, - () -> redisAutoConfiguration.reactiveStringRedisTemplate(context.getBean(ReactiveRedisConnectionFactory.class))); + context.registerBean("reactiveRedisTemplate", + ReactiveRedisTemplate.class, + () -> redisAutoConfiguration.reactiveRedisTemplate( + context.getBean(ReactiveRedisConnectionFactory.class), + context + ), + (definition) -> ((RootBeanDefinition) definition).setTargetType(ResolvableType.forClassWithGenerics( + ReactiveRedisTemplate.class, + Object.class, + Object.class + )) + ); + + context.registerBean("reactiveStringRedisTemplate", + ReactiveStringRedisTemplate.class, + () -> redisAutoConfiguration.reactiveStringRedisTemplate(context.getBean(ReactiveRedisConnectionFactory.class)) + ); } } diff --git a/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/SentinelInitializer.java b/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/SentinelInitializer.java index 71aa54f25..5a88bd492 100644 --- a/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/SentinelInitializer.java +++ b/autoconfigure-adapter-redis/src/main/java/org/springframework/boot/autoconfigure/data/redis/SentinelInitializer.java @@ -19,11 +19,17 @@ public SentinelInitializer(RedisProperties.Sentinel sentinel) { @Override public void initialize(GenericApplicationContext context) { if (sentinel != null) { - context.registerBean(RedisSentinelConfiguration.class, this::getRedisSentinelConfiguration); + context.registerBean( + RedisSentinelConfiguration.class, + this::getRedisSentinelConfiguration + ); } } private RedisSentinelConfiguration getRedisSentinelConfiguration() { - return new RedisSentinelConfiguration(sentinel.getMaster(), new HashSet<>(sentinel.getNodes())); + return new RedisSentinelConfiguration( + sentinel.getMaster(), + new HashSet<>(sentinel.getNodes()) + ); } } diff --git a/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/HttpSecurityInitializer.java b/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/HttpSecurityInitializer.java index 9594f6a9e..2f29f515e 100644 --- a/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/HttpSecurityInitializer.java +++ b/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/HttpSecurityInitializer.java @@ -6,6 +6,7 @@ import org.springframework.security.authentication.ProviderManager; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.config.annotation.ObjectPostProcessor; +import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.core.userdetails.UserDetailsPasswordService; import org.springframework.security.core.userdetails.UserDetailsService; @@ -18,64 +19,79 @@ * {@link ApplicationContextInitializer} adapter for {@link HttpSecurityConfiguration}. */ public class HttpSecurityInitializer implements ApplicationContextInitializer { - private static final String BEAN_NAME_PREFIX = "org.springframework.security.config.annotation.web.configuration.HttpSecurityConfiguration."; - static final String HTTPSECURITY_BEAN_NAME = BEAN_NAME_PREFIX + "httpSecurity"; + private static final String BEAN_NAME_PREFIX = "org.springframework.security.config.annotation.web.configuration.HttpSecurityConfiguration."; + static final String HTTPSECURITY_BEAN_NAME = BEAN_NAME_PREFIX + "httpSecurity"; - private final AuthenticationManager authenticationManager; - private final UserDetailsService userDetailsService; - private final PasswordEncoder passwordEncoder; - private final UserDetailsPasswordService userDetailsPasswordService; + private final AuthenticationManager authenticationManager; + private final UserDetailsService userDetailsService; + private final PasswordEncoder passwordEncoder; + private final UserDetailsPasswordService userDetailsPasswordService; - public HttpSecurityInitializer( - AuthenticationManager authenticationManager, UserDetailsService userDetailsService, - PasswordEncoder passwordEncoder, UserDetailsPasswordService userDetailsPasswordService) { - this.authenticationManager = authenticationManager; - this.userDetailsService = userDetailsService; - this.passwordEncoder = passwordEncoder; - this.userDetailsPasswordService = userDetailsPasswordService; - } + public HttpSecurityInitializer( + AuthenticationManager authenticationManager, + UserDetailsService userDetailsService, + PasswordEncoder passwordEncoder, + UserDetailsPasswordService userDetailsPasswordService + ) { + this.authenticationManager = authenticationManager; + this.userDetailsService = userDetailsService; + this.passwordEncoder = passwordEncoder; + this.userDetailsPasswordService = userDetailsPasswordService; + } - @SuppressWarnings("unchecked") - @Override - public void initialize(GenericApplicationContext context) { - HttpSecurityConfiguration configuration = new HttpSecurityConfiguration(); - configuration.setApplicationContext(context); + @SuppressWarnings("unchecked") + @Override + public void initialize(GenericApplicationContext context) { + HttpSecurityConfiguration configuration = new HttpSecurityConfiguration(); + configuration.setApplicationContext(context); - if (authenticationManager != null) { - configuration.setAuthenticationManager(authenticationManager); - } else { - // build authenticationManager, otherwise HttpSecurityConfiguration will throw NPE - DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); - authProvider.setUserDetailsService(userDetailsService); - authProvider.setUserDetailsPasswordService(userDetailsPasswordService); - if (passwordEncoder != null) { - authProvider.setPasswordEncoder(passwordEncoder); - } else { - authProvider.setPasswordEncoder(PasswordEncoderFactories.createDelegatingPasswordEncoder()); - } + AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration(); + authenticationConfiguration.setApplicationContext(context); - configuration.setAuthenticationManager(new ProviderManager(authProvider)); - } + configuration.setAuthenticationConfiguration(authenticationConfiguration); - Supplier httpSecuritySupplier = () -> { - configuration.setObjectPostProcessor(context.getBean(ObjectPostProcessor.class)); + if (authenticationManager != null) { + context.registerBean( + AuthenticationManager.class, + authenticationManager + ); + } else { + // build authenticationManager, otherwise HttpSecurityConfiguration will throw NPE + DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); + authProvider.setUserDetailsService(userDetailsService); + authProvider.setUserDetailsPasswordService(userDetailsPasswordService); - try { - return configuration.httpSecurity(); - } catch (Exception e) { - throw new IllegalStateException(e); - } - }; + if (passwordEncoder != null) { + authProvider.setPasswordEncoder(passwordEncoder); + } else { + authProvider.setPasswordEncoder(PasswordEncoderFactories.createDelegatingPasswordEncoder()); + } - context.registerBean( - HTTPSECURITY_BEAN_NAME, - HttpSecurity.class, - httpSecuritySupplier, - bd -> { - bd.setScope("prototype"); - bd.setAutowireCandidate(true); - } - ); - } + context.registerBean( + AuthenticationManager.class, + new ProviderManager(authProvider) + ); + } + + Supplier httpSecuritySupplier = () -> { + configuration.setObjectPostProcessor(context.getBean(ObjectPostProcessor.class)); + + try { + return configuration.httpSecurity(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + }; + + context.registerBean( + HTTPSECURITY_BEAN_NAME, + HttpSecurity.class, + httpSecuritySupplier, + bd -> { + bd.setScope("prototype"); + bd.setAutowireCandidate(true); + } + ); + } } diff --git a/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/ObjectPostProcessorInitializer.java b/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/ObjectPostProcessorInitializer.java index 004076071..e4d942f0e 100644 --- a/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/ObjectPostProcessorInitializer.java +++ b/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/ObjectPostProcessorInitializer.java @@ -10,9 +10,12 @@ */ public class ObjectPostProcessorInitializer implements ApplicationContextInitializer { - @Override - public void initialize(GenericApplicationContext context) { - ObjectPostProcessorConfiguration configuration = new ObjectPostProcessorConfiguration(); - context.registerBean(ObjectPostProcessor.class, () -> configuration.objectPostProcessor(context.getBeanFactory())); - } + @Override + public void initialize(GenericApplicationContext context) { + ObjectPostProcessorConfiguration configuration = new ObjectPostProcessorConfiguration(); + context.registerBean( + ObjectPostProcessor.class, + () -> configuration.objectPostProcessor(context.getBeanFactory()) + ); + } } diff --git a/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/WebMvcSecurityInitializer.java b/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/WebMvcSecurityInitializer.java index 713f210a8..4bfe4ae19 100644 --- a/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/WebMvcSecurityInitializer.java +++ b/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/WebMvcSecurityInitializer.java @@ -11,14 +11,19 @@ */ public class WebMvcSecurityInitializer implements ApplicationContextInitializer { - @Override - public void initialize(GenericApplicationContext context) { - Supplier configurationSupplier = () -> { - final WebMvcSecurityConfiguration configuration = new WebMvcSecurityConfiguration(); - configuration.setApplicationContext(context); - return configuration; - }; + @Override + public void initialize(GenericApplicationContext context) { + Supplier configurationSupplier = () -> { + final WebMvcSecurityConfiguration configuration = new WebMvcSecurityConfiguration(); + configuration.setApplicationContext(context); + return configuration; + }; - context.registerBean(RequestDataValueProcessor.class, () -> configurationSupplier.get().requestDataValueProcessor()); - } + context.registerBean( + RequestDataValueProcessor.class, + () -> configurationSupplier + .get() + .requestDataValueProcessor() + ); + } } diff --git a/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/WebSecurityInitializer.java b/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/WebSecurityInitializer.java index b0ba05424..906e1f033 100644 --- a/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/WebSecurityInitializer.java +++ b/autoconfigure-adapter-security/src/main/java/org/springframework/security/config/annotation/web/configuration/WebSecurityInitializer.java @@ -11,7 +11,7 @@ import org.springframework.security.web.access.WebInvocationPrivilegeEvaluator; import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; -import javax.servlet.Filter; +import jakarta.servlet.Filter; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -23,72 +23,78 @@ */ public class WebSecurityInitializer implements ApplicationContextInitializer { - private final Consumer httpSecurityDsl; + private final Consumer httpSecurityDsl; - public WebSecurityInitializer(Consumer httpSecurityDsl) { - this.httpSecurityDsl = httpSecurityDsl; - } + public WebSecurityInitializer(Consumer httpSecurityDsl) { + this.httpSecurityDsl = httpSecurityDsl; + } - @SuppressWarnings("unchecked") - @Override - public void initialize(GenericApplicationContext context) { + @SuppressWarnings("unchecked") + @Override + public void initialize(GenericApplicationContext context) { - Supplier configurationSupplier = new Supplier() { - private WebSecurityConfiguration configuration; + Supplier configurationSupplier = new Supplier() { + private WebSecurityConfiguration configuration; - @Override - public WebSecurityConfiguration get() { - if (configuration == null) { - configuration = new WebSecurityConfiguration(); - HttpSecurity httpSecurity = context.getBean(HttpSecurityInitializer.HTTPSECURITY_BEAN_NAME, HttpSecurity.class); + @Override + public WebSecurityConfiguration get() { + if (configuration == null) { + configuration = new WebSecurityConfiguration(); + HttpSecurity httpSecurity = context.getBean( + HttpSecurityInitializer.HTTPSECURITY_BEAN_NAME, + HttpSecurity.class + ); - if (httpSecurityDsl != null) { - httpSecurityDsl.accept(httpSecurity); - } + if (httpSecurityDsl != null) { + httpSecurityDsl.accept(httpSecurity); + } - try { - configuration.setFilterChains(Collections.singletonList(httpSecurity.build())); - } catch (Exception e) { - throw new IllegalStateException(e); - } + try { + configuration.setFilterChains(Collections.singletonList(httpSecurity.build())); + } catch (Exception e) { + throw new IllegalStateException(e); + } - List> webSecurityConfigurers = new ArrayList<>(); - String[] webSecurityConfigurerBeanNames = context.getBeanNamesForType( - ResolvableType.forClassWithGenerics(SecurityConfigurer.class, Filter.class, WebSecurity.class)); - for (String webSecurityConfigurerBeanName : webSecurityConfigurerBeanNames) { - webSecurityConfigurers.add((SecurityConfigurer) context.getBean(webSecurityConfigurerBeanName)); - } - try { - configuration.setFilterChainProxySecurityConfigurer(context.getBean(ObjectPostProcessor.class), webSecurityConfigurers); - } catch (Exception e) { - throw new IllegalStateException(e); - } - } - return configuration; - } - }; + try { + configuration.setFilterChainProxySecurityConfigurer( + context.getBean(ObjectPostProcessor.class), + context.getBeanFactory() + ); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return configuration; + } + }; - context.registerBean( - SecurityExpressionHandler.class, - () -> configurationSupplier.get().webSecurityExpressionHandler(), - bd -> bd.setDependsOn(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME) - ); - context.registerBean( - AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME, - Filter.class, - () -> { - try { - return configurationSupplier.get().springSecurityFilterChain(); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - ); - context.registerBean( - WebInvocationPrivilegeEvaluator.class, - () -> configurationSupplier.get().privilegeEvaluator(), - bd -> bd.setDependsOn(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME) - ); - } + context.registerBean( + SecurityExpressionHandler.class, + () -> configurationSupplier + .get() + .webSecurityExpressionHandler(), + bd -> bd.setDependsOn(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME) + ); + context.registerBean( + AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME, + Filter.class, + () -> { + try { + return configurationSupplier + .get() + .springSecurityFilterChain(); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + ); + context.registerBean( + WebInvocationPrivilegeEvaluator.class, + () -> configurationSupplier + .get() + .privilegeEvaluator(), + bd -> bd.setDependsOn(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME) + ); + } } diff --git a/autoconfigure-adapter-thymeleaf/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafInitializer.java b/autoconfigure-adapter-thymeleaf/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafInitializer.java index 5adfa2559..a39260fe3 100644 --- a/autoconfigure-adapter-thymeleaf/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafInitializer.java +++ b/autoconfigure-adapter-thymeleaf/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafInitializer.java @@ -18,9 +18,7 @@ import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; -import org.springframework.util.ClassUtils; -import org.thymeleaf.extras.java8time.dialect.Java8TimeDialect; -import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver; +import org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver; /** * {@link ApplicationContextInitializer} adapter for {@link ThymeleafAutoConfiguration}. @@ -35,10 +33,13 @@ public ThymeleafInitializer(ThymeleafProperties properties) { @Override public void initialize(GenericApplicationContext context) { - ThymeleafAutoConfiguration.DefaultTemplateResolverConfiguration templateResolverConfiguration = new ThymeleafAutoConfiguration.DefaultTemplateResolverConfiguration(this.properties, context); - context.registerBean(SpringResourceTemplateResolver.class, templateResolverConfiguration::defaultTemplateResolver); - if (ClassUtils.isPresent("org.thymeleaf.extras.java8time.dialect.Java8TimeDialect", null)) { - context.registerBean(Java8TimeDialect.class, () -> new ThymeleafAutoConfiguration.ThymeleafJava8TimeDialect().java8TimeDialect()); - } + ThymeleafAutoConfiguration.DefaultTemplateResolverConfiguration templateResolverConfiguration = new ThymeleafAutoConfiguration.DefaultTemplateResolverConfiguration( + this.properties, + context + ); + context.registerBean( + SpringResourceTemplateResolver.class, + templateResolverConfiguration::defaultTemplateResolver + ); } } diff --git a/autoconfigure-adapter-thymeleaf/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveWebInitializer.java b/autoconfigure-adapter-thymeleaf/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveWebInitializer.java index 0c3939834..fe676c34c 100644 --- a/autoconfigure-adapter-thymeleaf/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveWebInitializer.java +++ b/autoconfigure-adapter-thymeleaf/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveWebInitializer.java @@ -4,7 +4,7 @@ import org.springframework.context.support.GenericApplicationContext; import org.springframework.web.reactive.result.view.ViewResolver; import org.thymeleaf.dialect.IDialect; -import org.thymeleaf.spring5.SpringWebFluxTemplateEngine; +import org.thymeleaf.spring6.SpringWebFluxTemplateEngine; import org.thymeleaf.templateresolver.ITemplateResolver; /** @@ -22,7 +22,25 @@ public ThymeleafReactiveWebInitializer(ThymeleafProperties properties) { public void initialize(GenericApplicationContext context) { TemplateEngineConfigurations.ReactiveTemplateEngineConfiguration reactiveConfiguration = new TemplateEngineConfigurations.ReactiveTemplateEngineConfiguration(); ThymeleafAutoConfiguration.ThymeleafWebFluxConfiguration webFluxConfiguration = new ThymeleafAutoConfiguration.ThymeleafWebFluxConfiguration(); - context.registerBean("thymeleafTemplateEngine", SpringWebFluxTemplateEngine.class, () -> reactiveConfiguration.templateEngine(this.properties, context.getBeanProvider(ITemplateResolver.class), context.getBeanProvider(IDialect.class))); - context.registerBean(ViewResolver.class, () -> webFluxConfiguration.thymeleafViewResolver(context.getBean("thymeleafTemplateEngine", SpringWebFluxTemplateEngine.class), this.properties)); + + context.registerBean( + "thymeleafTemplateEngine", + SpringWebFluxTemplateEngine.class, + () -> reactiveConfiguration.templateEngine(this.properties, + context.getBeanProvider(ITemplateResolver.class), + context.getBeanProvider(IDialect.class) + ) + ); + + context.registerBean( + ViewResolver.class, + () -> webFluxConfiguration.thymeleafViewResolver( + context.getBean( + "thymeleafTemplateEngine", + SpringWebFluxTemplateEngine.class + ), + this.properties + ) + ); } } diff --git a/autoconfigure-adapter-thymeleaf/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletWebInitializer.java b/autoconfigure-adapter-thymeleaf/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletWebInitializer.java index 79c5eb9dd..329f126a3 100644 --- a/autoconfigure-adapter-thymeleaf/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletWebInitializer.java +++ b/autoconfigure-adapter-thymeleaf/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletWebInitializer.java @@ -20,7 +20,7 @@ import org.springframework.context.support.GenericApplicationContext; import org.springframework.web.servlet.ViewResolver; import org.thymeleaf.dialect.IDialect; -import org.thymeleaf.spring5.SpringTemplateEngine; +import org.thymeleaf.spring6.SpringTemplateEngine; import org.thymeleaf.templateresolver.ITemplateResolver; /** @@ -38,7 +38,26 @@ public ThymeleafServletWebInitializer(ThymeleafProperties properties) { public void initialize(GenericApplicationContext context) { TemplateEngineConfigurations.DefaultTemplateEngineConfiguration defaultConfiguration = new TemplateEngineConfigurations.DefaultTemplateEngineConfiguration(); ThymeleafAutoConfiguration.ThymeleafWebMvcConfiguration.ThymeleafViewResolverConfiguration webMvcConfiguration = new ThymeleafAutoConfiguration.ThymeleafWebMvcConfiguration.ThymeleafViewResolverConfiguration(); - context.registerBean("thymeleafTemplateEngine", SpringTemplateEngine.class, () -> defaultConfiguration.templateEngine(this.properties, context.getBeanProvider(ITemplateResolver.class), context.getBeanProvider(IDialect.class))); - context.registerBean("thymeleafViewResolver", ViewResolver.class, () -> webMvcConfiguration.thymeleafViewResolver(this.properties, context.getBean("thymeleafTemplateEngine", SpringTemplateEngine.class))); + + context.registerBean( + "thymeleafTemplateEngine", + SpringTemplateEngine.class, + () -> defaultConfiguration.templateEngine(this.properties, + context.getBeanProvider(ITemplateResolver.class), + context.getBeanProvider(IDialect.class) + ) + ); + + context.registerBean( + "thymeleafViewResolver", + ViewResolver.class, + () -> webMvcConfiguration.thymeleafViewResolver( + this.properties, + context.getBean( + "thymeleafTemplateEngine", + SpringTemplateEngine.class + ) + ) + ); } } diff --git a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/AbstractCodecInitializer.java b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/AbstractCodecInitializer.java index c2ba68144..d1e761037 100644 --- a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/AbstractCodecInitializer.java +++ b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/AbstractCodecInitializer.java @@ -1,6 +1,7 @@ package org.springframework.boot.autoconfigure.web.reactive; import java.util.Arrays; +import java.util.List; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientCodecCustomizer; @@ -11,21 +12,45 @@ public abstract class AbstractCodecInitializer implements ApplicationContextInitializer { - protected final boolean isClientCodec; + protected final boolean isClientCodec; - public AbstractCodecInitializer(boolean isClientCodec) { - this.isClientCodec = isClientCodec; - } + public AbstractCodecInitializer(boolean isClientCodec) { + this.isClientCodec = isClientCodec; + } - @Override - public void initialize(GenericApplicationContext context) { - if (isClientCodec) { - context.registerBean(BeanDefinitionReaderUtils.uniqueBeanName(WebClientCodecCustomizer.class.getName(), context), WebClientCodecCustomizer.class, () -> new WebClientCodecCustomizer(Arrays.asList((CodecCustomizer) configurer -> register(context, configurer)))); - } - else { - context.registerBean(BeanDefinitionReaderUtils.uniqueBeanName(CodecCustomizer.class.getName(), context), CodecCustomizer.class, () -> configurer -> register(context, configurer)); - } - } + @Override + public void initialize(GenericApplicationContext context) { + if (isClientCodec) { + context.registerBean( + BeanDefinitionReaderUtils.uniqueBeanName( + WebClientCodecCustomizer.class.getName(), + context + ), + WebClientCodecCustomizer.class, + () -> new WebClientCodecCustomizer( + List.of(configurer -> register( + context, + configurer + )) + ) + ); + } else { + context.registerBean( + BeanDefinitionReaderUtils.uniqueBeanName( + CodecCustomizer.class.getName(), + context + ), + CodecCustomizer.class, + () -> configurer -> register( + context, + configurer + ) + ); + } + } - protected abstract void register(GenericApplicationContext context, CodecConfigurer configurer); + protected abstract void register( + GenericApplicationContext context, + CodecConfigurer configurer + ); } diff --git a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/FormCodecInitializer.java b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/FormCodecInitializer.java index efd3aef4d..ae0f0b0ed 100644 --- a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/FormCodecInitializer.java +++ b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/FormCodecInitializer.java @@ -27,13 +27,21 @@ */ public class FormCodecInitializer extends AbstractCodecInitializer { - public FormCodecInitializer(boolean isClientCodec) { - super(isClientCodec); - } + public FormCodecInitializer(boolean isClientCodec) { + super(isClientCodec); + } - @Override - protected void register(GenericApplicationContext context, CodecConfigurer configurer) { - configurer.customCodecs().writer(new FormHttpMessageWriter()); - configurer.customCodecs().reader(new FormHttpMessageReader()); - } + @Override + protected void register( + GenericApplicationContext context, + CodecConfigurer configurer + ) { + configurer + .customCodecs() + .register(new FormHttpMessageWriter()); + + configurer + .customCodecs() + .register(new FormHttpMessageReader()); + } } diff --git a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/JacksonJsonCodecInitializer.java b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/JacksonJsonCodecInitializer.java index 92fbf1540..8c4a3461c 100644 --- a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/JacksonJsonCodecInitializer.java +++ b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/JacksonJsonCodecInitializer.java @@ -29,18 +29,30 @@ /** * {@link ApplicationContextInitializer} adapter for registering Jackson JSON codecs. */ -public class JacksonJsonCodecInitializer extends AbstractCodecInitializer { - - public JacksonJsonCodecInitializer(boolean isClientCodec) { - super(isClientCodec); - } - - @Override - protected void register(GenericApplicationContext context, CodecConfigurer configurer) { - ObjectMapper mapper = context.getBean(ObjectMapper.class); - Jackson2JsonEncoder encoder = new Jackson2JsonEncoder(mapper); - configurer.customCodecs().decoder(new Jackson2JsonDecoder(mapper)); - configurer.customCodecs().encoder(encoder); - configurer.customCodecs().writer(new ServerSentEventHttpMessageWriter(encoder)); - } +public class JacksonJsonCodecInitializer extends AbstractCodecInitializer { + + public JacksonJsonCodecInitializer(boolean isClientCodec) { + super(isClientCodec); + } + + @Override + protected void register( + GenericApplicationContext context, + CodecConfigurer configurer + ) { + ObjectMapper mapper = context.getBean(ObjectMapper.class); + Jackson2JsonEncoder encoder = new Jackson2JsonEncoder(mapper); + + configurer + .customCodecs() + .register(new Jackson2JsonDecoder(mapper)); + + configurer + .customCodecs() + .register(encoder); + + configurer + .customCodecs() + .register(new ServerSentEventHttpMessageWriter(encoder)); + } } diff --git a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/KotlinSerializationCodecInitializer.java b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/KotlinSerializationCodecInitializer.java index bde1448e1..79f3837d6 100644 --- a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/KotlinSerializationCodecInitializer.java +++ b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/KotlinSerializationCodecInitializer.java @@ -24,19 +24,27 @@ /** * {@link ApplicationContextInitializer} adapter for registering Kotlin serialization codecs. + * * @see KotlinSerializationJsonEncoder * @see KotlinSerializationJsonDecoder */ public class KotlinSerializationCodecInitializer extends AbstractCodecInitializer { - public KotlinSerializationCodecInitializer(boolean isClientCodec) { - super(isClientCodec); - } + public KotlinSerializationCodecInitializer(boolean isClientCodec) { + super(isClientCodec); + } - @Override - protected void register(GenericApplicationContext context, CodecConfigurer configurer) { - configurer.customCodecs().encoder(new KotlinSerializationJsonEncoder()); - configurer.customCodecs().decoder(new KotlinSerializationJsonDecoder()); + @Override + protected void register( + GenericApplicationContext context, + CodecConfigurer configurer + ) { + configurer + .customCodecs() + .register(new KotlinSerializationJsonEncoder()); - } + configurer + .customCodecs() + .register(new KotlinSerializationJsonDecoder()); + } } diff --git a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/MultipartCodecInitializer.java b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/MultipartCodecInitializer.java index b15c99acc..ac63521a1 100644 --- a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/MultipartCodecInitializer.java +++ b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/MultipartCodecInitializer.java @@ -26,17 +26,26 @@ /** * {@link ApplicationContextInitializer} adapter for registering multipart codecs. */ + public class MultipartCodecInitializer extends AbstractCodecInitializer { - public MultipartCodecInitializer(boolean isClientCodec) { - super(isClientCodec); - } + public MultipartCodecInitializer(boolean isClientCodec) { + super(isClientCodec); + } + + @Override + protected void register( + GenericApplicationContext context, + CodecConfigurer configurer + ) { + configurer + .customCodecs() + .register(new MultipartHttpMessageWriter()); - @Override - protected void register(GenericApplicationContext context, CodecConfigurer configurer) { - configurer.customCodecs().writer(new MultipartHttpMessageWriter()); - if (!isClientCodec) { - configurer.customCodecs().reader(new MultipartHttpMessageReader(new DefaultPartHttpMessageReader())); - } - } + if (!isClientCodec) { + configurer + .customCodecs() + .register(new MultipartHttpMessageReader(new DefaultPartHttpMessageReader())); + } + } } diff --git a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ProtobufCodecInitializer.java b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ProtobufCodecInitializer.java index abe229186..2ce55cae3 100644 --- a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ProtobufCodecInitializer.java +++ b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ProtobufCodecInitializer.java @@ -24,19 +24,27 @@ /** * {@link ApplicationContextInitializer} adapter for registering Protobuf codecs. + * * @see ProtobufEncoder * @see ProtobufDecoder */ public class ProtobufCodecInitializer extends AbstractCodecInitializer { - public ProtobufCodecInitializer(boolean isClientCodec) { - super(isClientCodec); - } + public ProtobufCodecInitializer(boolean isClientCodec) { + super(isClientCodec); + } - @Override - protected void register(GenericApplicationContext context, CodecConfigurer configurer) { - configurer.customCodecs().encoder(new ProtobufEncoder()); - configurer.customCodecs().decoder(new ProtobufDecoder()); + @Override + protected void register( + GenericApplicationContext context, + CodecConfigurer configurer + ) { + configurer + .customCodecs() + .register(new ProtobufEncoder()); - } + configurer + .customCodecs() + .register(new ProtobufDecoder()); + } } diff --git a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerInitializer.java b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerInitializer.java index 743a167b2..95593d07c 100644 --- a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerInitializer.java +++ b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerInitializer.java @@ -58,72 +58,273 @@ /** * {@link ApplicationContextInitializer} adapter for Reactive webflux server auto-configurations. */ -@SuppressWarnings("deprecation") public class ReactiveWebServerInitializer implements ApplicationContextInitializer { - private final ServerProperties serverProperties; - - private final WebProperties webProperties; - - private final ConfigurableReactiveWebServerFactory serverFactory; - - private final WebFluxProperties webFluxProperties; - - - public ReactiveWebServerInitializer(ServerProperties serverProperties, WebProperties webProperties, WebFluxProperties webFluxProperties, ConfigurableReactiveWebServerFactory serverFactory) { - this.serverProperties = serverProperties; - this.webProperties = webProperties; - this.webFluxProperties = webFluxProperties; - this.serverFactory = serverFactory; - } - - @Override - public void initialize(GenericApplicationContext context) { - context.registerBean("webServerFactoryCustomizerBeanPostProcessor", WebServerFactoryCustomizerBeanPostProcessor.class, WebServerFactoryCustomizerBeanPostProcessor::new); - - context.registerBean(ReactiveWebServerFactoryCustomizer.class, () -> new ReactiveWebServerFactoryCustomizer(this.serverProperties)); - context.registerBean(ConfigurableReactiveWebServerFactory.class, () -> serverFactory); - context.registerBean(ErrorAttributes.class, DefaultErrorAttributes::new); - context.registerBean(ErrorWebExceptionHandler.class, () -> { - ErrorWebFluxAutoConfiguration errorConfiguration = new ErrorWebFluxAutoConfiguration(this.serverProperties); - return errorConfiguration.errorWebExceptionHandler(context.getBean(ErrorAttributes.class), this.webProperties, context.getBeanProvider(ViewResolver.class), context.getBean(SERVER_CODEC_CONFIGURER_BEAN_NAME, ServerCodecConfigurer.class), context); - }); - context.registerBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class, () -> new EnableWebFluxConfigurationWrapper(context, webFluxProperties, webProperties)); - context.registerBean(LOCALE_CONTEXT_RESOLVER_BEAN_NAME, LocaleContextResolver.class, () -> context.getBean(EnableWebFluxConfigurationWrapper.class).localeContextResolver()); - context.registerBean("responseStatusExceptionHandler", WebExceptionHandler.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).responseStatusExceptionHandler()); - - context.registerBean(RouterFunctionMapping.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).routerFunctionMapping(context.getBean(SERVER_CODEC_CONFIGURER_BEAN_NAME, ServerCodecConfigurer.class))); - context.registerBean(SERVER_CODEC_CONFIGURER_BEAN_NAME, ServerCodecConfigurer.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).serverCodecConfigurer()); - context.registerBean("webFluxAdapterRegistry", ReactiveAdapterRegistry.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).webFluxAdapterRegistry()); - context.registerBean("handlerFunctionAdapter", HandlerFunctionAdapter.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).handlerFunctionAdapter()); - context.registerBean("webFluxContentTypeResolver", RequestedContentTypeResolver.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).webFluxContentTypeResolver()); - context.registerBean("webFluxConversionService", FormattingConversionService.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).webFluxConversionService()); - context.registerBean("serverResponseResultHandler", ServerResponseResultHandler.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).serverResponseResultHandler(context.getBean(SERVER_CODEC_CONFIGURER_BEAN_NAME, ServerCodecConfigurer.class))); - context.registerBean("simpleHandlerAdapter", SimpleHandlerAdapter.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).simpleHandlerAdapter()); - context.registerBean("viewResolutionResultHandler", ViewResolutionResultHandler.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).viewResolutionResultHandler(context.getBean("webFluxAdapterRegistry", ReactiveAdapterRegistry.class), context.getBean("webFluxContentTypeResolver", RequestedContentTypeResolver.class))); - context.registerBean("webFluxValidator", Validator.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).webFluxValidator()); - context.registerBean(HttpHandler.class, () -> applicationContext(context).build()); - context.registerBean(WEB_HANDLER_BEAN_NAME, DispatcherHandler.class, (Supplier) DispatcherHandler::new); - context.registerBean(WebFluxConfig.class, () -> new WebFluxConfig(webProperties, webFluxProperties, context, context.getBeanProvider(HandlerMethodArgumentResolver.class), context.getBeanProvider(CodecCustomizer.class), - context.getBeanProvider(ResourceHandlerRegistrationCustomizer.class), context.getBeanProvider(ViewResolver.class))); - } - - private class EnableWebFluxConfigurationWrapper extends EnableWebFluxConfiguration { - - public EnableWebFluxConfigurationWrapper(GenericApplicationContext context, WebFluxProperties webFluxProperties, WebProperties webProperties) { - super(webFluxProperties, webProperties, serverProperties, context.getBeanProvider(WebFluxRegistrations.class)); - setConfigurers(new ArrayList<>(context.getBeansOfType(WebFluxConfigurer.class).values())); - } - - @Override - public ServerCodecConfigurer serverCodecConfigurer() { - ServerCodecConfigurer configurer = ServerCodecConfigurer.create(); - configurer.registerDefaults(false); - getApplicationContext().getBeanProvider(CodecCustomizer.class) - .forEach((customizer) -> customizer.customize(configurer)); - return configurer; - } - - - } + private final ServerProperties serverProperties; + + private final WebProperties webProperties; + + private final ConfigurableReactiveWebServerFactory serverFactory; + + private final WebFluxProperties webFluxProperties; + + + public ReactiveWebServerInitializer( + ServerProperties serverProperties, + WebProperties webProperties, + WebFluxProperties webFluxProperties, + ConfigurableReactiveWebServerFactory serverFactory + ) { + this.serverProperties = serverProperties; + this.webProperties = webProperties; + this.webFluxProperties = webFluxProperties; + this.serverFactory = serverFactory; + } + + @Override + public void initialize(GenericApplicationContext context) { + context.registerBean( + "webServerFactoryCustomizerBeanPostProcessor", + WebServerFactoryCustomizerBeanPostProcessor.class, + WebServerFactoryCustomizerBeanPostProcessor::new + ); + + context.registerBean( + ReactiveWebServerFactoryCustomizer.class, + () -> new ReactiveWebServerFactoryCustomizer(this.serverProperties) + ); + + context.registerBean( + ConfigurableReactiveWebServerFactory.class, + () -> serverFactory + ); + + context.registerBean( + ErrorAttributes.class, + DefaultErrorAttributes::new + ); + + context.registerBean( + ErrorWebExceptionHandler.class, + () -> { + ErrorWebFluxAutoConfiguration errorConfiguration = new ErrorWebFluxAutoConfiguration(this.serverProperties); + return errorConfiguration.errorWebExceptionHandler( + context.getBean(ErrorAttributes.class), + this.webProperties, + context.getBeanProvider(ViewResolver.class), + context.getBean( + SERVER_CODEC_CONFIGURER_BEAN_NAME, + ServerCodecConfigurer.class + ), + context + ); + } + ); + + context.registerBean( + "fuWebFluxConfiguration", + EnableWebFluxConfigurationWrapper.class, + () -> new EnableWebFluxConfigurationWrapper(context, + webFluxProperties, + webProperties + ) + ); + + context.registerBean( + LOCALE_CONTEXT_RESOLVER_BEAN_NAME, + LocaleContextResolver.class, + () -> context + .getBean(EnableWebFluxConfigurationWrapper.class) + .localeContextResolver() + ); + + context.registerBean( + "responseStatusExceptionHandler", + WebExceptionHandler.class, + () -> context + .getBean( + "fuWebFluxConfiguration", + EnableWebFluxConfigurationWrapper.class + ) + .responseStatusExceptionHandler() + ); + + context.registerBean( + RouterFunctionMapping.class, + () -> context + .getBean( + "fuWebFluxConfiguration", + EnableWebFluxConfigurationWrapper.class + ) + .routerFunctionMapping(context.getBean( + SERVER_CODEC_CONFIGURER_BEAN_NAME, + ServerCodecConfigurer.class + )) + ); + + context.registerBean( + SERVER_CODEC_CONFIGURER_BEAN_NAME, + ServerCodecConfigurer.class, + () -> context + .getBean( + "fuWebFluxConfiguration", + EnableWebFluxConfigurationWrapper.class + ) + .serverCodecConfigurer() + ); + + context.registerBean( + "webFluxAdapterRegistry", + ReactiveAdapterRegistry.class, + () -> context + .getBean( + "fuWebFluxConfiguration", + EnableWebFluxConfigurationWrapper.class + ) + .webFluxAdapterRegistry() + ); + + context.registerBean( + "handlerFunctionAdapter", + HandlerFunctionAdapter.class, + () -> context + .getBean( + "fuWebFluxConfiguration", + EnableWebFluxConfigurationWrapper.class + ) + .handlerFunctionAdapter() + ); + + context.registerBean( + "webFluxContentTypeResolver", + RequestedContentTypeResolver.class, + () -> context + .getBean( + "fuWebFluxConfiguration", + EnableWebFluxConfigurationWrapper.class + ) + .webFluxContentTypeResolver() + ); + + context.registerBean( + "webFluxConversionService", + FormattingConversionService.class, + () -> context + .getBean( + "fuWebFluxConfiguration", + EnableWebFluxConfigurationWrapper.class + ) + .webFluxConversionService() + ); + + context.registerBean( + "serverResponseResultHandler", + ServerResponseResultHandler.class, + () -> context + .getBean( + "fuWebFluxConfiguration", + EnableWebFluxConfigurationWrapper.class + ) + .serverResponseResultHandler(context.getBean( + SERVER_CODEC_CONFIGURER_BEAN_NAME, + ServerCodecConfigurer.class + )) + ); + + context.registerBean( + "simpleHandlerAdapter", + SimpleHandlerAdapter.class, + () -> context + .getBean( + "fuWebFluxConfiguration", + EnableWebFluxConfigurationWrapper.class + ) + .simpleHandlerAdapter() + ); + + context.registerBean( + "viewResolutionResultHandler", + ViewResolutionResultHandler.class, + () -> context + .getBean( + "fuWebFluxConfiguration", + EnableWebFluxConfigurationWrapper.class + ) + .viewResolutionResultHandler( + context.getBean( + "webFluxAdapterRegistry", + ReactiveAdapterRegistry.class + ), + context.getBean( + "webFluxContentTypeResolver", + RequestedContentTypeResolver.class + ) + ) + ); + + context.registerBean( + "webFluxValidator", + Validator.class, + () -> context + .getBean( + "fuWebFluxConfiguration", + EnableWebFluxConfigurationWrapper.class + ) + .webFluxValidator() + ); + + context.registerBean( + HttpHandler.class, + () -> applicationContext(context).build() + ); + + context.registerBean( + WEB_HANDLER_BEAN_NAME, + DispatcherHandler.class, + (Supplier) DispatcherHandler::new + ); + + context.registerBean( + WebFluxConfig.class, + () -> new WebFluxConfig(webProperties, + webFluxProperties, + context, + context.getBeanProvider(HandlerMethodArgumentResolver.class), + context.getBeanProvider(CodecCustomizer.class), + context.getBeanProvider(ResourceHandlerRegistrationCustomizer.class), + context.getBeanProvider(ViewResolver.class) + ) + ); + } + + private class EnableWebFluxConfigurationWrapper extends EnableWebFluxConfiguration { + + public EnableWebFluxConfigurationWrapper( + GenericApplicationContext context, + WebFluxProperties webFluxProperties, + WebProperties webProperties + ) { + super( + webFluxProperties, + webProperties, + serverProperties, + context.getBeanProvider(WebFluxRegistrations.class) + ); + setConfigurers(new ArrayList<>(context + .getBeansOfType(WebFluxConfigurer.class) + .values())); + } + + @Override + public ServerCodecConfigurer serverCodecConfigurer() { + ServerCodecConfigurer configurer = ServerCodecConfigurer.create(); + configurer.registerDefaults(false); + getApplicationContext() + .getBeanProvider(CodecCustomizer.class) + .forEach((customizer) -> customizer.customize(configurer)); + return configurer; + } + + + } } diff --git a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ResourceCodecInitializer.java b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ResourceCodecInitializer.java index 48ce946ff..cc04afbc4 100644 --- a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ResourceCodecInitializer.java +++ b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ResourceCodecInitializer.java @@ -28,13 +28,21 @@ */ public class ResourceCodecInitializer extends AbstractCodecInitializer { - public ResourceCodecInitializer(boolean isClientCodec) { - super(isClientCodec); - } + public ResourceCodecInitializer(boolean isClientCodec) { + super(isClientCodec); + } - @Override - protected void register(GenericApplicationContext context, CodecConfigurer configurer) { - configurer.customCodecs().writer(new ResourceHttpMessageWriter()); - configurer.customCodecs().decoder(new ResourceDecoder()); - } + @Override + protected void register( + GenericApplicationContext context, + CodecConfigurer configurer + ) { + configurer + .customCodecs() + .register(new ResourceHttpMessageWriter()); + + configurer + .customCodecs() + .register(new ResourceDecoder()); + } } diff --git a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/StringCodecInitializer.java b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/StringCodecInitializer.java index 39339193a..891b90d56 100644 --- a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/StringCodecInitializer.java +++ b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/StringCodecInitializer.java @@ -27,16 +27,27 @@ */ public class StringCodecInitializer extends AbstractCodecInitializer { - private final boolean textPlainOnly; + private final boolean textPlainOnly; - public StringCodecInitializer(boolean isClientCodec, boolean textPlainOnly) { - super(isClientCodec); - this.textPlainOnly = textPlainOnly; - } + public StringCodecInitializer( + boolean isClientCodec, + boolean textPlainOnly + ) { + super(isClientCodec); + this.textPlainOnly = textPlainOnly; + } - @Override - protected void register(GenericApplicationContext context, CodecConfigurer configurer) { - configurer.customCodecs().encoder(textPlainOnly ? CharSequenceEncoder.textPlainOnly() : CharSequenceEncoder.allMimeTypes()); - configurer.customCodecs().decoder(textPlainOnly ? StringDecoder.textPlainOnly() : StringDecoder.allMimeTypes()); - } + @Override + protected void register( + GenericApplicationContext context, + CodecConfigurer configurer + ) { + configurer + .customCodecs() + .register(textPlainOnly ? CharSequenceEncoder.textPlainOnly() : CharSequenceEncoder.allMimeTypes()); + + configurer + .customCodecs() + .register(textPlainOnly ? StringDecoder.textPlainOnly() : StringDecoder.allMimeTypes()); + } } diff --git a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ReactiveWebClientBuilderInitializer.java b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ReactiveWebClientBuilderInitializer.java index 44c2b1bac..43bac581c 100644 --- a/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ReactiveWebClientBuilderInitializer.java +++ b/autoconfigure-adapter-web-reactive/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ReactiveWebClientBuilderInitializer.java @@ -31,40 +31,67 @@ */ public class ReactiveWebClientBuilderInitializer implements ApplicationContextInitializer { - private final String baseUrl; + private final String baseUrl; - public ReactiveWebClientBuilderInitializer(String baseUrl) { - this.baseUrl = baseUrl; - } + public ReactiveWebClientBuilderInitializer(String baseUrl) { + this.baseUrl = baseUrl; + } - @Override - public void initialize(GenericApplicationContext context) { - context.registerBean(WebClient.Builder.class, () -> new WebClientAutoConfiguration().webClientBuilder(context.getBeanProvider(WebClientCustomizer.class))); - context.registerBean(DefaultWebClientCodecCustomizer.class, () -> new DefaultWebClientCodecCustomizer(this.baseUrl, new ArrayList<>(context.getBeansOfType(CodecCustomizer.class).values()))); - } + @Override + public void initialize(GenericApplicationContext context) { + context.registerBean( + WebClient.Builder.class, + () -> new WebClientAutoConfiguration().webClientBuilder( + context.getBeanProvider(WebClientCustomizer.class) + ) + ); - /** - * Variant of {@link WebClientCodecCustomizer} that configure empty default codecs by defaults - */ - static public class DefaultWebClientCodecCustomizer implements WebClientCustomizer { + context.registerBean( + DefaultWebClientCodecCustomizer.class, + () -> new DefaultWebClientCodecCustomizer( + this.baseUrl, + new ArrayList<>( + context + .getBeansOfType(CodecCustomizer.class) + .values() + ) + ) + ); + } - private final List codecCustomizers; + /** + * Variant of {@link WebClientCodecCustomizer} that configure empty default codecs by defaults + */ + static public class DefaultWebClientCodecCustomizer implements WebClientCustomizer { - private final String baseUrl; + private final List codecCustomizers; - public DefaultWebClientCodecCustomizer(String baseUrl, List codecCustomizers) { - this.codecCustomizers = codecCustomizers; - this.baseUrl = baseUrl; - } + private final String baseUrl; - @Override - public void customize(WebClient.Builder builder) { - builder.exchangeStrategies(ExchangeStrategies.empty() - .codecs(codecs -> this.codecCustomizers - .forEach((customizer) -> customizer.customize(codecs))).build()); - if (this.baseUrl != null) { - builder.baseUrl(this.baseUrl); - } - } - } + public DefaultWebClientCodecCustomizer( + String baseUrl, + List codecCustomizers + ) { + this.codecCustomizers = codecCustomizers; + this.baseUrl = baseUrl; + } + + @Override + public void customize(WebClient.Builder builder) { + builder.exchangeStrategies( + ExchangeStrategies + .empty() + .codecs( + codecs -> this + .codecCustomizers + .forEach((customizer) -> customizer.customize(codecs)) + ) + .build() + ); + + if (this.baseUrl != null) { + builder.baseUrl(this.baseUrl); + } + } + } } diff --git a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/AtomConverterInitializer.java b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/AtomConverterInitializer.java index 410eacfb8..f1a445276 100644 --- a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/AtomConverterInitializer.java +++ b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/AtomConverterInitializer.java @@ -7,8 +7,12 @@ public class AtomConverterInitializer implements ApplicationContextInitializer { - @Override - public void initialize(GenericApplicationContext context) { - context.registerBean("atomFeedHttpMessageConverter", HttpMessageConverter.class, AtomFeedHttpMessageConverter::new); - } + @Override + public void initialize(GenericApplicationContext context) { + context.registerBean( + "atomFeedHttpMessageConverter", + HttpMessageConverter.class, + AtomFeedHttpMessageConverter::new + ); + } } diff --git a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/FormConverterInitializer.java b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/FormConverterInitializer.java index 39a29eacc..2d1b29ae6 100644 --- a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/FormConverterInitializer.java +++ b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/FormConverterInitializer.java @@ -7,8 +7,12 @@ public class FormConverterInitializer implements ApplicationContextInitializer { - @Override - public void initialize(GenericApplicationContext context) { - context.registerBean("allEncompassingFormHttpMessageConverter", HttpMessageConverter.class, AllEncompassingFormHttpMessageConverter::new); - } + @Override + public void initialize(GenericApplicationContext context) { + context.registerBean( + "allEncompassingFormHttpMessageConverter", + HttpMessageConverter.class, + AllEncompassingFormHttpMessageConverter::new + ); + } } diff --git a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/JacksonJsonConverterInitializer.java b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/JacksonJsonConverterInitializer.java index 7cc604b00..3167d10e6 100644 --- a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/JacksonJsonConverterInitializer.java +++ b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/JacksonJsonConverterInitializer.java @@ -9,8 +9,12 @@ public class JacksonJsonConverterInitializer implements ApplicationContextInitializer { - @Override - public void initialize(GenericApplicationContext context) { - context.registerBean("mappingJackson2HttpMessageConverter", HttpMessageConverter.class, () -> new MappingJackson2HttpMessageConverter(context.getBean(ObjectMapper.class))); - } + @Override + public void initialize(GenericApplicationContext context) { + context.registerBean( + "mappingJackson2HttpMessageConverter", + HttpMessageConverter.class, + () -> new MappingJackson2HttpMessageConverter(context.getBean(ObjectMapper.class)) + ); + } } diff --git a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/KotlinSerializationConverterInitializer.java b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/KotlinSerializationConverterInitializer.java index c79540e37..37608ea6d 100644 --- a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/KotlinSerializationConverterInitializer.java +++ b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/KotlinSerializationConverterInitializer.java @@ -25,8 +25,12 @@ public class KotlinSerializationConverterInitializer implements ApplicationContextInitializer { - @Override - public void initialize(GenericApplicationContext context) { - context.registerBean("kotlinSerializationJsonHttpMessageConverter", HttpMessageConverter.class, (Supplier) KotlinSerializationJsonHttpMessageConverter::new); - } + @Override + public void initialize(GenericApplicationContext context) { + context.registerBean( + "kotlinSerializationJsonHttpMessageConverter", + HttpMessageConverter.class, + (Supplier) KotlinSerializationJsonHttpMessageConverter::new + ); + } } diff --git a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ResourceConverterInitializer.java b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ResourceConverterInitializer.java index 392f7198f..570fbf653 100644 --- a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ResourceConverterInitializer.java +++ b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ResourceConverterInitializer.java @@ -10,9 +10,18 @@ public class ResourceConverterInitializer implements ApplicationContextInitializer { - @Override - public void initialize(GenericApplicationContext context) { - context.registerBean("resourceHttpMessageConverter", HttpMessageConverter.class, (Supplier) ResourceHttpMessageConverter::new); - context.registerBean("resourceRegionHttpMessageConverter", HttpMessageConverter.class, ResourceRegionHttpMessageConverter::new); - } + @Override + public void initialize(GenericApplicationContext context) { + context.registerBean( + "resourceHttpMessageConverter", + HttpMessageConverter.class, + (Supplier) ResourceHttpMessageConverter::new + ); + + context.registerBean( + "resourceRegionHttpMessageConverter", + HttpMessageConverter.class, + ResourceRegionHttpMessageConverter::new + ); + } } diff --git a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/RssConverterInitializer.java b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/RssConverterInitializer.java index efbb5c705..6e45ab928 100644 --- a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/RssConverterInitializer.java +++ b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/RssConverterInitializer.java @@ -7,8 +7,12 @@ public class RssConverterInitializer implements ApplicationContextInitializer { - @Override - public void initialize(GenericApplicationContext context) { - context.registerBean("rssChannelHttpMessageConverter", HttpMessageConverter.class, RssChannelHttpMessageConverter::new); - } + @Override + public void initialize(GenericApplicationContext context) { + context.registerBean( + "rssChannelHttpMessageConverter", + HttpMessageConverter.class, + RssChannelHttpMessageConverter::new + ); + } } diff --git a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerInitializer.java b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerInitializer.java index f973e8788..15d5c257d 100644 --- a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerInitializer.java +++ b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerInitializer.java @@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.http.HttpMessageConverters; import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.WebProperties; +import org.springframework.boot.ssl.SslBundles; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor; import org.springframework.boot.web.servlet.FilterRegistrationBean; @@ -45,7 +46,7 @@ import java.util.List; import java.util.function.Supplier; -import javax.servlet.MultipartConfigElement; +import jakarta.servlet.MultipartConfigElement; import static org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration.*; import static org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.EnableWebMvcConfiguration; @@ -57,120 +58,370 @@ @SuppressWarnings("deprecation") public class ServletWebServerInitializer implements ApplicationContextInitializer { - private final ServerProperties serverProperties; - - private final ConfigurableServletWebServerFactory serverFactory; - - private final WebMvcProperties webMvcProperties; - - private final WebProperties webProperties; - - - public ServletWebServerInitializer(ServerProperties serverProperties, WebMvcProperties webMvcProperties, WebProperties webProperties, ConfigurableServletWebServerFactory serverFactory) { - this.serverProperties = serverProperties; - this.webMvcProperties = webMvcProperties; - this.webProperties = webProperties; - this.serverFactory = serverFactory; - } - - @Override - public void initialize(GenericApplicationContext context) { - context.registerBean("webServerFactoryCustomizerBeanPostProcessor", WebServerFactoryCustomizerBeanPostProcessor.class, WebServerFactoryCustomizerBeanPostProcessor::new); - context.registerBean(WebMvcProperties.class, () -> this.webMvcProperties); - context.registerBean(BeanPostProcessorsRegistrar.class, BeanPostProcessorsRegistrar::new); - context.registerBean(ConfigurableServletWebServerFactory.class, () -> serverFactory); - ServletWebServerFactoryAutoConfiguration servletWebServerFactoryConfiguration = new ServletWebServerFactoryAutoConfiguration(); - context.registerBean(ServletWebServerFactoryCustomizer.class, () -> servletWebServerFactoryConfiguration.servletWebServerFactoryCustomizer(serverProperties, context.getBeanProvider(WebListenerRegistrar.class), context.getBeanProvider(CookieSameSiteSupplier.class))); - if (serverFactory instanceof TomcatServletWebServerFactory) { - context.registerBean(TomcatServletWebServerFactoryCustomizer.class, () -> servletWebServerFactoryConfiguration.tomcatServletWebServerFactoryCustomizer(serverProperties)); - context.registerBean(ForwardedHeaderFilterCustomizer.class, () -> new ForwardedHeaderFilterConfiguration().tomcatForwardedHeaderFilterCustomizer(serverProperties)); - } - context.registerBean(FilterRegistrationBean.class, () -> new ForwardedHeaderFilterConfiguration().forwardedHeaderFilter(context.getBeanProvider(ForwardedHeaderFilterCustomizer.class))); - - DispatcherServletAutoConfiguration.DispatcherServletConfiguration dispatcherServletConfiguration = new DispatcherServletAutoConfiguration.DispatcherServletConfiguration(); - context.registerBean(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME, DispatcherServlet.class, () -> dispatcherServletConfiguration.dispatcherServlet(webMvcProperties)); - context.registerBean(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME, DispatcherServletRegistrationBean.class, () -> new DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration().dispatcherServletRegistration(context.getBean(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME, DispatcherServlet.class), webMvcProperties, context.getBeanProvider(MultipartConfigElement.class))); - - WebMvcAutoConfiguration webMvcConfiguration = new WebMvcAutoConfiguration(); - context.registerBean(OrderedHiddenHttpMethodFilter.class, webMvcConfiguration::hiddenHttpMethodFilter); - - Supplier webMvcConfigurationAdapter = new Supplier() { - - private WebMvcAutoConfigurationAdapter configuration; - - @Override - public WebMvcAutoConfigurationAdapter get() { - if (configuration == null) { - configuration = new WebMvcAutoConfigurationAdapter(webProperties, webMvcProperties, context, context.getBeanProvider(HttpMessageConverters.class), context.getBeanProvider(ResourceHandlerRegistrationCustomizer.class), context.getBeanProvider(DispatcherServletPath.class), context.getBeanProvider(ResolvableType.forClass(ServletRegistrationBean.class))); - return configuration; - } - return configuration; - } - }; - context.registerBean(InternalResourceViewResolver.class, () -> webMvcConfigurationAdapter.get().defaultViewResolver()); - context.registerBean(BeanNameViewResolver.class, () -> webMvcConfigurationAdapter.get().beanNameViewResolver()); - context.registerBean("viewResolver", ContentNegotiatingViewResolver.class, () -> webMvcConfigurationAdapter.get().viewResolver(context)); - context.registerBean(RequestContextFilter.class, WebMvcAutoConfigurationAdapter::requestContextFilter); - // TODO Favicon management - - Supplier enableWebMvcConfiguration = new Supplier() { - - private EnableWebMvcConfiguration configuration; - - @Override - public EnableWebMvcConfiguration get() { - if (configuration == null) { - configuration = new EnableWebMvcConfigurationWrapper(context.getBeanProvider(WebMvcRegistrations.class), - context.getBeanProvider(ResourceHandlerRegistrationCustomizer.class), context); - configuration.setApplicationContext(context); - configuration.setServletContext(((WebApplicationContext) context).getServletContext()); - configuration.setResourceLoader(context); - } - return configuration; - } - }; - - context.registerBean(FormattingConversionService.class, () -> enableWebMvcConfiguration.get().mvcConversionService()); - context.registerBean(Validator.class, () -> enableWebMvcConfiguration.get().mvcValidator()); - context.registerBean(ContentNegotiationManager.class, () -> enableWebMvcConfiguration.get().mvcContentNegotiationManager()); - context.registerBean(ResourceChainResourceHandlerRegistrationCustomizer.class, () -> new ResourceChainCustomizerConfiguration().resourceHandlerRegistrationCustomizer(webProperties)); - context.registerBean(PathMatcher.class, () -> enableWebMvcConfiguration.get().mvcPathMatcher()); - context.registerBean(UrlPathHelper.class, () -> enableWebMvcConfiguration.get().mvcUrlPathHelper()); - context.registerBean(HandlerMapping.class, () -> enableWebMvcConfiguration.get().viewControllerHandlerMapping(context.getBean(FormattingConversionService.class), context.getBean(ResourceUrlProvider.class))); - context.registerBean(RouterFunctionMapping.class, () -> enableWebMvcConfiguration.get().routerFunctionMapping(context.getBean(FormattingConversionService.class), context.getBean(ResourceUrlProvider.class))); - context.registerBean(HandlerMapping.class, () -> enableWebMvcConfiguration.get().resourceHandlerMapping(context.getBean(ContentNegotiationManager.class), context.getBean(FormattingConversionService.class), context.getBean(ResourceUrlProvider.class))); - context.registerBean(ResourceUrlProvider.class, () -> enableWebMvcConfiguration.get().mvcResourceUrlProvider()); - context.registerBean(HandlerMapping.class, () -> enableWebMvcConfiguration.get().defaultServletHandlerMapping()); - context.registerBean(HandlerFunctionAdapter.class, () -> enableWebMvcConfiguration.get().handlerFunctionAdapter()); - context.registerBean(HttpRequestHandlerAdapter.class, () -> enableWebMvcConfiguration.get().httpRequestHandlerAdapter()); - context.registerBean(SimpleControllerHandlerAdapter.class, () -> enableWebMvcConfiguration.get().simpleControllerHandlerAdapter()); - context.registerBean(HandlerExceptionResolver.class, () -> enableWebMvcConfiguration.get().handlerExceptionResolver(context.getBean(ContentNegotiationManager.class))); - context.registerBean(ViewResolver.class, () -> enableWebMvcConfiguration.get().mvcViewResolver(context.getBean(ContentNegotiationManager.class))); - context.registerBean("mvcHandlerMappingIntrospector", HandlerMappingIntrospector.class, () -> enableWebMvcConfiguration.get().mvcHandlerMappingIntrospector(), bd -> bd.setLazyInit(true)); - context.registerBean(WelcomePageHandlerMapping.class, () -> enableWebMvcConfiguration.get().welcomePageHandlerMapping(context, context.getBean(FormattingConversionService.class), context.getBean(ResourceUrlProvider.class))); - context.registerBean(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, LocaleResolver.class, () -> enableWebMvcConfiguration.get().localeResolver()); - context.registerBean(DispatcherServlet.THEME_RESOLVER_BEAN_NAME, ThemeResolver.class, () -> enableWebMvcConfiguration.get().themeResolver()); - context.registerBean(DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME, FlashMapManager.class, () -> enableWebMvcConfiguration.get().flashMapManager()); - context.registerBean(DispatcherServlet.REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME, RequestToViewNameTranslator.class, () -> enableWebMvcConfiguration.get().viewNameTranslator()); - } - - private class EnableWebMvcConfigurationWrapper extends EnableWebMvcConfiguration { - - public EnableWebMvcConfigurationWrapper( - ObjectProvider mvcRegistrationsProvider, - ObjectProvider resourceHandlerRegistrationCustomizerProvider, - ListableBeanFactory beanFactory) { - super(webMvcProperties, webProperties, mvcRegistrationsProvider, resourceHandlerRegistrationCustomizerProvider, beanFactory); - } - - @Override - protected void configureMessageConverters(List> converters) { - getApplicationContext().getBeanProvider(HttpMessageConverter.class).orderedStream().forEach(converters::add); - } - - @Override - protected void configureHandlerExceptionResolvers(List exceptionResolvers) { - exceptionResolvers.add(new DefaultHandlerExceptionResolver()); - } - } + private final ServerProperties serverProperties; + + private final ConfigurableServletWebServerFactory serverFactory; + + private final WebMvcProperties webMvcProperties; + + private final WebProperties webProperties; + + + public ServletWebServerInitializer( + ServerProperties serverProperties, + WebMvcProperties webMvcProperties, + WebProperties webProperties, + ConfigurableServletWebServerFactory serverFactory + ) { + this.serverProperties = serverProperties; + this.webMvcProperties = webMvcProperties; + this.webProperties = webProperties; + this.serverFactory = serverFactory; + } + + @Override + public void initialize(GenericApplicationContext context) { + context.registerBean( + "webServerFactoryCustomizerBeanPostProcessor", + WebServerFactoryCustomizerBeanPostProcessor.class, + WebServerFactoryCustomizerBeanPostProcessor::new + ); + context.registerBean( + WebMvcProperties.class, + () -> this.webMvcProperties + ); + + context.registerBean( + BeanPostProcessorsRegistrar.class, + BeanPostProcessorsRegistrar::new + ); + + context.registerBean( + ConfigurableServletWebServerFactory.class, + () -> serverFactory + ); + + ServletWebServerFactoryAutoConfiguration servletWebServerFactoryConfiguration = new ServletWebServerFactoryAutoConfiguration(); + context.registerBean( + ServletWebServerFactoryCustomizer.class, + () -> servletWebServerFactoryConfiguration.servletWebServerFactoryCustomizer( + serverProperties, + context.getBeanProvider(WebListenerRegistrar.class), + context.getBeanProvider(CookieSameSiteSupplier.class), + context.getBeanProvider(SslBundles.class) + ) + ); + + if (serverFactory instanceof TomcatServletWebServerFactory) { + context.registerBean( + TomcatServletWebServerFactoryCustomizer.class, + () -> servletWebServerFactoryConfiguration.tomcatServletWebServerFactoryCustomizer(serverProperties) + ); + + context.registerBean( + ForwardedHeaderFilterCustomizer.class, + () -> new ForwardedHeaderFilterConfiguration().tomcatForwardedHeaderFilterCustomizer(serverProperties) + ); + } + + context.registerBean( + FilterRegistrationBean.class, + () -> new ForwardedHeaderFilterConfiguration().forwardedHeaderFilter(context.getBeanProvider(ForwardedHeaderFilterCustomizer.class)) + ); + + DispatcherServletAutoConfiguration.DispatcherServletConfiguration dispatcherServletConfiguration = new DispatcherServletAutoConfiguration.DispatcherServletConfiguration(); + context.registerBean( + DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME, + DispatcherServlet.class, + () -> dispatcherServletConfiguration.dispatcherServlet(webMvcProperties) + ); + + context.registerBean( + DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME, + DispatcherServletRegistrationBean.class, + () -> new DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration().dispatcherServletRegistration( + context.getBean( + DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME, + DispatcherServlet.class + ), + webMvcProperties, + context.getBeanProvider(MultipartConfigElement.class) + ) + ); + + WebMvcAutoConfiguration webMvcConfiguration = new WebMvcAutoConfiguration(); + context.registerBean( + OrderedHiddenHttpMethodFilter.class, + webMvcConfiguration::hiddenHttpMethodFilter + ); + + Supplier webMvcConfigurationAdapter = new Supplier() { + + private WebMvcAutoConfigurationAdapter configuration; + + @Override + public WebMvcAutoConfigurationAdapter get() { + if (configuration == null) { + configuration = new WebMvcAutoConfigurationAdapter( + webProperties, + webMvcProperties, + context, + context.getBeanProvider(HttpMessageConverters.class), + context.getBeanProvider(ResourceHandlerRegistrationCustomizer.class), + context.getBeanProvider(DispatcherServletPath.class), + context.getBeanProvider(ResolvableType.forClass(ServletRegistrationBean.class)) + ); + return configuration; + } + return configuration; + } + }; + + context.registerBean( + InternalResourceViewResolver.class, + () -> webMvcConfigurationAdapter + .get() + .defaultViewResolver() + ); + + context.registerBean( + BeanNameViewResolver.class, + () -> webMvcConfigurationAdapter + .get() + .beanNameViewResolver() + ); + + context.registerBean( + "viewResolver", + ContentNegotiatingViewResolver.class, + () -> webMvcConfigurationAdapter + .get() + .viewResolver(context) + ); + + context.registerBean( + RequestContextFilter.class, + WebMvcAutoConfigurationAdapter::requestContextFilter + ); + // TODO Favicon management + + Supplier enableWebMvcConfiguration = new Supplier() { + + private EnableWebMvcConfiguration configuration; + + @Override + public EnableWebMvcConfiguration get() { + if (configuration == null) { + configuration = new EnableWebMvcConfigurationWrapper(context.getBeanProvider(WebMvcRegistrations.class), + context.getBeanProvider(ResourceHandlerRegistrationCustomizer.class), + context + ); + configuration.setApplicationContext(context); + configuration.setServletContext(((WebApplicationContext) context).getServletContext()); + configuration.setResourceLoader(context); + } + return configuration; + } + }; + + context.registerBean( + FormattingConversionService.class, + () -> enableWebMvcConfiguration + .get() + .mvcConversionService() + ); + + context.registerBean( + Validator.class, + () -> enableWebMvcConfiguration + .get() + .mvcValidator() + ); + + context.registerBean( + ContentNegotiationManager.class, + () -> enableWebMvcConfiguration + .get() + .mvcContentNegotiationManager() + ); + + context.registerBean( + ResourceChainResourceHandlerRegistrationCustomizer.class, + () -> new ResourceChainCustomizerConfiguration().resourceHandlerRegistrationCustomizer(webProperties) + ); + + context.registerBean( + PathMatcher.class, + () -> enableWebMvcConfiguration + .get() + .mvcPathMatcher() + ); + + context.registerBean( + UrlPathHelper.class, + () -> enableWebMvcConfiguration + .get() + .mvcUrlPathHelper() + ); + + context.registerBean( + HandlerMapping.class, + () -> enableWebMvcConfiguration + .get() + .viewControllerHandlerMapping( + context.getBean(FormattingConversionService.class), + context.getBean(ResourceUrlProvider.class) + ) + ); + + context.registerBean( + RouterFunctionMapping.class, + () -> enableWebMvcConfiguration + .get() + .routerFunctionMapping( + context.getBean(FormattingConversionService.class), + context.getBean(ResourceUrlProvider.class) + ) + ); + + context.registerBean( + HandlerMapping.class, + () -> enableWebMvcConfiguration + .get() + .resourceHandlerMapping(context.getBean(ContentNegotiationManager.class), + context.getBean(FormattingConversionService.class), + context.getBean(ResourceUrlProvider.class) + ) + ); + + context.registerBean( + ResourceUrlProvider.class, + () -> enableWebMvcConfiguration + .get() + .mvcResourceUrlProvider() + ); + + context.registerBean( + HandlerMapping.class, + () -> enableWebMvcConfiguration + .get() + .defaultServletHandlerMapping() + ); + + context.registerBean( + HandlerFunctionAdapter.class, + () -> enableWebMvcConfiguration + .get() + .handlerFunctionAdapter() + ); + + context.registerBean( + HttpRequestHandlerAdapter.class, + () -> enableWebMvcConfiguration + .get() + .httpRequestHandlerAdapter() + ); + + context.registerBean( + SimpleControllerHandlerAdapter.class, + () -> enableWebMvcConfiguration + .get() + .simpleControllerHandlerAdapter() + ); + + context.registerBean( + HandlerExceptionResolver.class, + () -> enableWebMvcConfiguration + .get() + .handlerExceptionResolver(context.getBean(ContentNegotiationManager.class)) + ); + + context.registerBean( + ViewResolver.class, + () -> enableWebMvcConfiguration + .get() + .mvcViewResolver(context.getBean(ContentNegotiationManager.class)) + ); + + context.registerBean( + "mvcHandlerMappingIntrospector", + HandlerMappingIntrospector.class, + () -> enableWebMvcConfiguration + .get() + .mvcHandlerMappingIntrospector(), + bd -> bd.setLazyInit(true) + ); + + context.registerBean( + WelcomePageHandlerMapping.class, + () -> enableWebMvcConfiguration + .get() + .welcomePageHandlerMapping(context, + context.getBean(FormattingConversionService.class), + context.getBean(ResourceUrlProvider.class) + ) + ); + + context.registerBean( + DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, + LocaleResolver.class, + () -> enableWebMvcConfiguration + .get() + .localeResolver() + ); + + context.registerBean( + DispatcherServlet.THEME_RESOLVER_BEAN_NAME, + ThemeResolver.class, + () -> enableWebMvcConfiguration + .get() + .themeResolver() + ); + + context.registerBean( + DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME, + FlashMapManager.class, + () -> enableWebMvcConfiguration + .get() + .flashMapManager() + ); + + context.registerBean( + DispatcherServlet.REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME, + RequestToViewNameTranslator.class, + () -> enableWebMvcConfiguration + .get() + .viewNameTranslator() + ); + } + + private class EnableWebMvcConfigurationWrapper extends EnableWebMvcConfiguration { + + public EnableWebMvcConfigurationWrapper( + ObjectProvider mvcRegistrationsProvider, + ObjectProvider resourceHandlerRegistrationCustomizerProvider, + ListableBeanFactory beanFactory + ) { + super( + webMvcProperties, + webProperties, + mvcRegistrationsProvider, + resourceHandlerRegistrationCustomizerProvider, + beanFactory + ); + } + + @Override + protected void configureMessageConverters(List> converters) { + getApplicationContext() + .getBeanProvider(HttpMessageConverter.class) + .orderedStream() + .forEach(converters::add); + } + + @Override + protected void configureHandlerExceptionResolvers(List exceptionResolvers) { + exceptionResolvers.add(new DefaultHandlerExceptionResolver()); + } + } } diff --git a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/StringConverterInitializer.java b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/StringConverterInitializer.java index 5eded501b..1465aef18 100644 --- a/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/StringConverterInitializer.java +++ b/autoconfigure-adapter-web-servlet/src/main/java/org/springframework/boot/autoconfigure/web/servlet/StringConverterInitializer.java @@ -28,8 +28,12 @@ */ public class StringConverterInitializer implements ApplicationContextInitializer { - @Override - public void initialize(GenericApplicationContext context) { - context.registerBean("StringHttpMessageConverter", HttpMessageConverter.class, (Supplier) StringHttpMessageConverter::new); - } + @Override + public void initialize(GenericApplicationContext context) { + context.registerBean( + "StringHttpMessageConverter", + HttpMessageConverter.class, + (Supplier) StringHttpMessageConverter::new + ); + } } diff --git a/kofu-cassandra/src/main/kotlin/org/springframework/fu/kofu/cassandra/CassandraDsl.kt b/kofu-cassandra/src/main/kotlin/org/springframework/fu/kofu/cassandra/CassandraDsl.kt index b6b1f654b..29a31d80b 100644 --- a/kofu-cassandra/src/main/kotlin/org/springframework/fu/kofu/cassandra/CassandraDsl.kt +++ b/kofu-cassandra/src/main/kotlin/org/springframework/fu/kofu/cassandra/CassandraDsl.kt @@ -73,15 +73,6 @@ open class CassandraDsl(private val init: CassandraDsl.() -> Unit) : AbstractDsl properties.contactPoints.addAll(value) } - /** - * Enable SSL support - */ - var ssl: Boolean - get() = properties.isSsl - set(value) { - properties.isSsl = value - } - /** * Configure the compression supported by the Cassandra binary protocol. */ @@ -91,10 +82,17 @@ open class CassandraDsl(private val init: CassandraDsl.() -> Unit) : AbstractDsl properties.compression = value } + /** + * Enable SSL support + */ + fun ssl(dsl: CassandraProperties.Ssl.() -> Unit = {}) { + properties.ssl.dsl() + } + /** * Configure the connection. */ - fun connection(dsl: CassandraProperties.Connection.() -> Unit = {}) { + fun connection(dsl: CassandraProperties.Connection.() -> Unit = {}) { properties.connection.dsl() } diff --git a/kofu-cassandra/src/main/kotlin/org/springframework/fu/kofu/cassandra/ReactiveCassandraDsl.kt b/kofu-cassandra/src/main/kotlin/org/springframework/fu/kofu/cassandra/ReactiveCassandraDsl.kt index a85a8cee9..c2f3234df 100644 --- a/kofu-cassandra/src/main/kotlin/org/springframework/fu/kofu/cassandra/ReactiveCassandraDsl.kt +++ b/kofu-cassandra/src/main/kotlin/org/springframework/fu/kofu/cassandra/ReactiveCassandraDsl.kt @@ -16,13 +16,13 @@ import org.springframework.fu.kofu.ConfigurationDsl * @sample org.springframework.fu.kofu.samples.reactiveCassandra */ open class ReactiveCassandraDsl(private val initBlock: ReactiveCassandraDsl.() -> Unit) : CassandraDsl({}) { - override fun initialize(context: GenericApplicationContext){ - super.initialize(context) - initBlock() - CassandraInitializer(properties).initialize(context) - CassandraDataInitializer(properties).initialize(context) - CassandraReactiveDataInitializer().initialize(context) - } + override fun initialize(context: GenericApplicationContext) { + super.initialize(context) + initBlock() + CassandraInitializer(properties).initialize(context) + CassandraDataInitializer(properties).initialize(context) + CassandraReactiveDataInitializer().initialize(context) + } } /** @@ -30,5 +30,5 @@ open class ReactiveCassandraDsl(private val initBlock: ReactiveCassandraDsl.() - * @see ReactiveCassandraDsl */ fun ConfigurationDsl.reactiveCassandra(dsl: ReactiveCassandraDsl.() -> Unit = {}) { - ReactiveCassandraDsl(dsl).initialize(context) + ReactiveCassandraDsl(dsl).initialize(context) } diff --git a/kofu-elasticsearch/build.gradle.kts b/kofu-elasticsearch/build.gradle.kts index 1e09631e5..27a1c0508 100644 --- a/kofu-elasticsearch/build.gradle.kts +++ b/kofu-elasticsearch/build.gradle.kts @@ -14,6 +14,9 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("org.springframework.data:spring-data-elasticsearch") + implementation("org.elasticsearch.client:elasticsearch-rest-high-level-client:7.17.5") { + exclude("commons-logging:commons-logging") + } testImplementation("org.junit.jupiter:junit-jupiter-api") testImplementation("org.springframework:spring-test") @@ -22,4 +25,7 @@ dependencies { testImplementation("org.testcontainers:testcontainers") testImplementation("org.springframework.data:spring-data-elasticsearch") + testImplementation("org.elasticsearch.client:elasticsearch-rest-high-level-client:7.17.5") { + exclude("commons-logging:commons-logging") + } } diff --git a/kofu-jdbc/src/main/kotlin/org/springframework/fu/kofu/jdbc/JdbcDsl.kt b/kofu-jdbc/src/main/kotlin/org/springframework/fu/kofu/jdbc/JdbcDsl.kt index fe98c4afc..0df51e26d 100644 --- a/kofu-jdbc/src/main/kotlin/org/springframework/fu/kofu/jdbc/JdbcDsl.kt +++ b/kofu-jdbc/src/main/kotlin/org/springframework/fu/kofu/jdbc/JdbcDsl.kt @@ -1,19 +1,12 @@ package org.springframework.fu.kofu.jdbc import org.springframework.boot.autoconfigure.jdbc.* -import org.springframework.boot.jdbc.DataSourceInitializationMode import org.springframework.context.support.GenericApplicationContext import org.springframework.fu.kofu.AbstractDsl import org.springframework.fu.kofu.ConfigurationDsl class JdbcDsl(private val datasourceType: DataSourceType, private val init: JdbcDsl.() -> Unit) : AbstractDsl() { - var schema = listOf() - - var data = listOf() - - var initializationMode = DataSourceInitializationMode.EMBEDDED - var url: String? = null var name: String? = null @@ -32,9 +25,6 @@ class JdbcDsl(private val datasourceType: DataSourceType, private val init: Jdbc val jdbcProperties = JdbcProperties() val dataSourceProperties = DataSourceProperties().apply { - schema = this@JdbcDsl.schema - data = this@JdbcDsl.data - initializationMode = this@JdbcDsl.initializationMode url = this@JdbcDsl.url name = this@JdbcDsl.name username = this@JdbcDsl.username diff --git a/kofu-jooq/src/main/kotlin/org/springframework/fu/kofu/jooq/JooqDsl.kt b/kofu-jooq/src/main/kotlin/org/springframework/fu/kofu/jooq/JooqDsl.kt index 89dd853fb..6f48db2d1 100644 --- a/kofu-jooq/src/main/kotlin/org/springframework/fu/kofu/jooq/JooqDsl.kt +++ b/kofu-jooq/src/main/kotlin/org/springframework/fu/kofu/jooq/JooqDsl.kt @@ -4,7 +4,6 @@ import org.jooq.SQLDialect import org.springframework.boot.autoconfigure.jdbc.* import org.springframework.boot.autoconfigure.jooq.JooqConfigurationInitializer import org.springframework.boot.autoconfigure.jooq.JooqProperties -import org.springframework.boot.jdbc.DataSourceInitializationMode import org.springframework.context.support.GenericApplicationContext import org.springframework.fu.kofu.AbstractDsl import org.springframework.fu.kofu.ConfigurationDsl @@ -19,8 +18,6 @@ class JooqDsl(private val datasourceType: DataSourceType, private val init: Jooq var data = listOf() - var initializationMode = DataSourceInitializationMode.EMBEDDED - var url: String? = null var name: String? = null @@ -39,9 +36,6 @@ class JooqDsl(private val datasourceType: DataSourceType, private val init: Jooq val jdbcProperties = JdbcProperties() val dataSourceProperties = DataSourceProperties().apply { - schema = this@JooqDsl.schema - data = this@JooqDsl.data - initializationMode = this@JooqDsl.initializationMode url = this@JooqDsl.url name = this@JooqDsl.name username = this@JooqDsl.username diff --git a/kofu-mongo/build.gradle.kts b/kofu-mongo/build.gradle.kts index e9d84d13f..fac39c318 100644 --- a/kofu-mongo/build.gradle.kts +++ b/kofu-mongo/build.gradle.kts @@ -13,7 +13,6 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-reflect") - compileOnly("de.flapdoodle.embed:de.flapdoodle.embed.mongo.spring30x:4.7.0") compileOnly("org.mongodb:mongodb-driver-legacy") compileOnly("org.mongodb:mongodb-driver-reactivestreams") implementation("org.springframework.data:spring-data-mongodb") @@ -25,7 +24,6 @@ dependencies { testImplementation("org.testcontainers:testcontainers") testImplementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive") - testImplementation("de.flapdoodle.embed:de.flapdoodle.embed.mongo.spring30x:4.7.0") testImplementation("org.mongodb:mongodb-driver-legacy") testImplementation("org.mongodb:mongodb-driver-reactivestreams") } diff --git a/kofu-mongo/src/main/kotlin/org/springframework/fu/kofu/mongo/AbstractMongoDsl.kt b/kofu-mongo/src/main/kotlin/org/springframework/fu/kofu/mongo/AbstractMongoDsl.kt index 885688257..4dffe0405 100644 --- a/kofu-mongo/src/main/kotlin/org/springframework/fu/kofu/mongo/AbstractMongoDsl.kt +++ b/kofu-mongo/src/main/kotlin/org/springframework/fu/kofu/mongo/AbstractMongoDsl.kt @@ -16,11 +16,7 @@ package org.springframework.fu.kofu.mongo -import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion -import de.flapdoodle.embed.mongo.distribution.Version import org.springframework.boot.autoconfigure.mongo.MongoProperties -import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoInitializer -import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoProperties import org.springframework.context.support.GenericApplicationContext import org.springframework.fu.kofu.AbstractDsl @@ -43,39 +39,4 @@ abstract class AbstractMongoDsl(private val init: MongoDsl.() -> Unit) : Abstrac set(value) { properties.uri = value } - - /** - * Enable MongoDB embedded webFlux. - * - * Require `de.flapdoodle.embed:de.flapdoodle.embed.mongo.spring30x:4.7.0` dependency. - * - * @sample org.springframework.fu.kofu.samples.mongoEmbedded - */ - fun embedded(version: IFeatureAwareVersion, dsl: EmbeddedMongoDsl.() -> Unit = {}) { - embedded = true - EmbeddedMongoDsl(properties, version, dsl).initialize(context) - } - - /** - * Kofu DSL for embedded MongoDB configuration. - */ - class EmbeddedMongoDsl(private val mongoProperties: MongoProperties, version: IFeatureAwareVersion, private val init: EmbeddedMongoDsl.() -> Unit) : AbstractDsl() { - - private val embeddedMongoProperties = EmbeddedMongoProperties() - - override fun initialize(context: GenericApplicationContext) { - super.initialize(context) - embeddedMongoProperties.version = version.asInDownloadPath() - init() - EmbeddedMongoInitializer(mongoProperties, embeddedMongoProperties).initialize(context) - } - - /** - * Version of Mongo to use - */ - var version: IFeatureAwareVersion = Version.Main.PRODUCTION - set(value) { - embeddedMongoProperties.version = value.asInDownloadPath() - } - } } diff --git a/kofu-mongo/src/main/kotlin/org/springframework/fu/kofu/mongo/ReactiveMongoDsl.kt b/kofu-mongo/src/main/kotlin/org/springframework/fu/kofu/mongo/ReactiveMongoDsl.kt index 23c473ac0..b637bc7b3 100644 --- a/kofu-mongo/src/main/kotlin/org/springframework/fu/kofu/mongo/ReactiveMongoDsl.kt +++ b/kofu-mongo/src/main/kotlin/org/springframework/fu/kofu/mongo/ReactiveMongoDsl.kt @@ -40,7 +40,7 @@ open class ReactiveMongoDsl( super.initialize(context) init() MongoReactiveDataInitializer(properties).initialize(context) - MongoReactiveInitializer(properties, embedded).initialize(context) + MongoReactiveInitializer(properties).initialize(context) } } diff --git a/kofu-redis/src/main/kotlin/org/springframework/fu/kofu/redis/AbstractRedisDsl.kt b/kofu-redis/src/main/kotlin/org/springframework/fu/kofu/redis/AbstractRedisDsl.kt index 81c52fd4c..203713d3d 100644 --- a/kofu-redis/src/main/kotlin/org/springframework/fu/kofu/redis/AbstractRedisDsl.kt +++ b/kofu-redis/src/main/kotlin/org/springframework/fu/kofu/redis/AbstractRedisDsl.kt @@ -72,11 +72,9 @@ open class AbstractRedisDsl : AbstractDsl() { /** * Configure whether to enable SSL support. */ - var ssl: Boolean - get() = properties.isSsl - set(value) { - properties.isSsl = value - } + fun ssl(dsl: RedisProperties.Ssl.() -> Unit = {}) { + properties.ssl.dsl() + } /** * Configure the redis sentinel properties via a [dedicated DSL][SentinelDsl]. diff --git a/kofu-redis/src/main/kotlin/org/springframework/fu/kofu/redis/ReactiveRedisDsl.kt b/kofu-redis/src/main/kotlin/org/springframework/fu/kofu/redis/ReactiveRedisDsl.kt index de7cfd019..465651be2 100644 --- a/kofu-redis/src/main/kotlin/org/springframework/fu/kofu/redis/ReactiveRedisDsl.kt +++ b/kofu-redis/src/main/kotlin/org/springframework/fu/kofu/redis/ReactiveRedisDsl.kt @@ -14,7 +14,6 @@ import org.springframework.fu.kofu.ConfigurationDsl * @author Waldemar Panas * @author Sebastien Deleuze */ -@Suppress("UsePropertyAccessSyntax") class ReactiveRedisDsl(private val init: ReactiveRedisDsl.() -> Unit) : AbstractRedisDsl(), LettuceRedisSupporter { private var lettuceInitializer: ApplicationContextInitializer? = null diff --git a/kofu-redis/src/main/kotlin/org/springframework/fu/kofu/redis/RedisDsl.kt b/kofu-redis/src/main/kotlin/org/springframework/fu/kofu/redis/RedisDsl.kt index 3366c14e1..faaa4dd7c 100644 --- a/kofu-redis/src/main/kotlin/org/springframework/fu/kofu/redis/RedisDsl.kt +++ b/kofu-redis/src/main/kotlin/org/springframework/fu/kofu/redis/RedisDsl.kt @@ -15,7 +15,6 @@ import org.springframework.fu.kofu.ConfigurationDsl * @author Waldemar Panas * @author Sebastien Deleuze */ -@Suppress("UsePropertyAccessSyntax") class RedisDsl(private val init: RedisDsl.() -> Unit) : AbstractRedisDsl(), JedisRedisSupporter, LettuceRedisSupporter { private var jedisInitializer: ApplicationContextInitializer? = null diff --git a/kofu-templating-thymeleaf/src/main/kotlin/org/springframework/fu/kofu/templating/ThymeleafDsl.kt b/kofu-templating-thymeleaf/src/main/kotlin/org/springframework/fu/kofu/templating/ThymeleafDsl.kt index e348acb97..98e99b41f 100644 --- a/kofu-templating-thymeleaf/src/main/kotlin/org/springframework/fu/kofu/templating/ThymeleafDsl.kt +++ b/kofu-templating-thymeleaf/src/main/kotlin/org/springframework/fu/kofu/templating/ThymeleafDsl.kt @@ -32,6 +32,7 @@ import org.springframework.fu.kofu.webmvc.WebMvcServerDsl * * Required dependencies can be retrieve using `org.springframework.boot:spring-boot-starter-thymeleaf`. */ +@Suppress("SetterBackingFieldAssignment") class ThymeleafDsl(private val init: ThymeleafDsl.() -> Unit) : AbstractDsl() { private val properties = ThymeleafProperties() diff --git a/kofu-webflux/src/main/kotlin/org/springframework/fu/kofu/webflux/WebFluxServerDsl.kt b/kofu-webflux/src/main/kotlin/org/springframework/fu/kofu/webflux/WebFluxServerDsl.kt index 1599959b2..11ecf8787 100644 --- a/kofu-webflux/src/main/kotlin/org/springframework/fu/kofu/webflux/WebFluxServerDsl.kt +++ b/kofu-webflux/src/main/kotlin/org/springframework/fu/kofu/webflux/WebFluxServerDsl.kt @@ -42,7 +42,6 @@ import org.springframework.web.server.WebFilter * @see WebFluxServerDsl.mustache * @author Sebastien Deleuze */ -@Suppress("DEPRECATION") open class WebFluxServerDsl(private val init: WebFluxServerDsl.() -> Unit): AbstractDsl() { private val serverProperties = ServerProperties() diff --git a/kofu-webmvc/src/main/kotlin/org/springframework/fu/kofu/webmvc/WebMvcCorsDsl.kt b/kofu-webmvc/src/main/kotlin/org/springframework/fu/kofu/webmvc/WebMvcCorsDsl.kt index ebba76d61..3d7bc72e6 100644 --- a/kofu-webmvc/src/main/kotlin/org/springframework/fu/kofu/webmvc/WebMvcCorsDsl.kt +++ b/kofu-webmvc/src/main/kotlin/org/springframework/fu/kofu/webmvc/WebMvcCorsDsl.kt @@ -29,23 +29,23 @@ import org.springframework.web.filter.CorsFilter * @author Sebastien Deleuze */ class WebMvcCorsDsl( - defaults: Boolean = true, - private val init: AbstractCorsDsl.() -> Unit + defaults: Boolean = true, + private val init: AbstractCorsDsl.() -> Unit ) : AbstractCorsDsl(defaults) { - private val source = UrlBasedCorsConfigurationSource() + private val source = UrlBasedCorsConfigurationSource() - override fun registerCorsConfiguration(path: String, configuration: CorsConfiguration) { - source.registerCorsConfiguration(path, configuration) - } + override fun registerCorsConfiguration(path: String, configuration: CorsConfiguration) { + source.registerCorsConfiguration(path, configuration) + } - override fun initialize(context: GenericApplicationContext) { - super.initialize(context) - init() - context.registerBean("corsFilter") { - CorsFilter(source) - } - } + override fun initialize(context: GenericApplicationContext) { + super.initialize(context) + init() + context.registerBean("corsFilter") { + CorsFilter(source) + } + } } /** @@ -58,7 +58,9 @@ class WebMvcCorsDsl( * @param dsl Cors DSL * @sample org.springframework.fu.kofu.samples.corsDsl */ -fun WebMvcServerDsl.cors(defaults: Boolean = true, - dsl: AbstractCorsDsl.() -> Unit = {}) { - WebMvcCorsDsl(defaults, dsl).initialize(context) +fun WebMvcServerDsl.cors( + defaults: Boolean = true, + dsl: AbstractCorsDsl.() -> Unit = {} +) { + WebMvcCorsDsl(defaults, dsl).initialize(context) } diff --git a/kofu-webmvc/src/main/kotlin/org/springframework/fu/kofu/webmvc/WebMvcSecurityDsl.kt b/kofu-webmvc/src/main/kotlin/org/springframework/fu/kofu/webmvc/WebMvcSecurityDsl.kt index a7532735d..9745fe712 100644 --- a/kofu-webmvc/src/main/kotlin/org/springframework/fu/kofu/webmvc/WebMvcSecurityDsl.kt +++ b/kofu-webmvc/src/main/kotlin/org/springframework/fu/kofu/webmvc/WebMvcSecurityDsl.kt @@ -21,12 +21,12 @@ import org.springframework.beans.factory.getBeanProvider import org.springframework.context.support.GenericApplicationContext import org.springframework.fu.kofu.AbstractDsl import org.springframework.security.authentication.AuthenticationManager +import org.springframework.security.config.annotation.web.HttpSecurityDsl import org.springframework.security.config.annotation.web.configuration.HttpSecurityInitializer import org.springframework.security.config.annotation.web.configuration.ObjectPostProcessorInitializer import org.springframework.security.config.annotation.web.configuration.WebMvcSecurityInitializer import org.springframework.security.config.annotation.web.configuration.WebSecurityInitializer -import org.springframework.security.config.web.servlet.HttpSecurityDsl -import org.springframework.security.config.web.servlet.invoke +import org.springframework.security.config.annotation.web.invoke import org.springframework.security.core.userdetails.UserDetailsPasswordService import org.springframework.security.core.userdetails.UserDetailsService import org.springframework.security.crypto.password.PasswordEncoder @@ -43,44 +43,47 @@ import org.springframework.security.web.context.SecurityContextRepository */ class WebMvcSecurityDsl(private val init: WebMvcSecurityDsl.() -> Unit) : AbstractDsl() { - var authenticationManager: AuthenticationManager? = null + var authenticationManager: AuthenticationManager? = null - var userDetailsService: UserDetailsService? = null + var userDetailsService: UserDetailsService? = null - var passwordEncoder: PasswordEncoder? = null + var passwordEncoder: PasswordEncoder? = null - var userDetailsPasswordService: UserDetailsPasswordService? = null + var userDetailsPasswordService: UserDetailsPasswordService? = null - var securityContextRepository: SecurityContextRepository? = null + var securityContextRepository: SecurityContextRepository? = null - private var httpConfiguration: HttpSecurityDsl.() -> Unit = {} + private var httpConfiguration: HttpSecurityDsl.() -> Unit = {} - fun http(httpConfiguration: HttpSecurityDsl.() -> Unit = {}) { - this.httpConfiguration = httpConfiguration - } + fun http(httpConfiguration: HttpSecurityDsl.() -> Unit = {}) { + this.httpConfiguration = httpConfiguration + } - override fun initialize(context: GenericApplicationContext) { - super.initialize(context) - init() + override fun initialize(context: GenericApplicationContext) { + super.initialize(context) + init() - ObjectPostProcessorInitializer().initialize(context) + ObjectPostProcessorInitializer().initialize(context) - val securityInitializer = HttpSecurityInitializer(authenticationManager, userDetailsService, passwordEncoder, - userDetailsPasswordService) + val securityInitializer = HttpSecurityInitializer( + authenticationManager, userDetailsService, passwordEncoder, + userDetailsPasswordService + ) - securityInitializer.initialize(context) + securityInitializer.initialize(context) - WebSecurityInitializer { - if (securityContextRepository != null) { - it.securityContext().securityContextRepository(securityContextRepository).and() - } else { - it - } - .invoke(httpConfiguration) - } - .initialize(context) - WebMvcSecurityInitializer().initialize(context) - } + WebSecurityInitializer { + if (securityContextRepository != null) { + @Suppress("DEPRECATION", "removal") + it.securityContext().securityContextRepository(securityContextRepository).and() + } else { + it + } + .invoke(httpConfiguration) + } + .initialize(context) + WebMvcSecurityInitializer().initialize(context) + } } /** @@ -93,7 +96,7 @@ class WebMvcSecurityDsl(private val init: WebMvcSecurityDsl.() -> Unit) : Abstra * @author Fred Montariol */ fun WebMvcServerDsl.security(dsl: WebMvcSecurityDsl.() -> Unit = {}) { - WebMvcSecurityDsl(dsl).initialize(context) + WebMvcSecurityDsl(dsl).initialize(context) } /** @@ -105,8 +108,8 @@ fun WebMvcServerDsl.security(dsl: WebMvcSecurityDsl.() -> Unit = {}) { * @param T type the bean must match, can be an interface or superclass */ inline fun WebMvcSecurityDsl.ref(name: String? = null): T = when (name) { - null -> context.getBean(T::class.java) - else -> context.getBean(name, T::class.java) + null -> context.getBean(T::class.java) + else -> context.getBean(name, T::class.java) } /** @@ -115,4 +118,4 @@ inline fun WebMvcSecurityDsl.ref(name: String? = null): T = wh * TODO Update when SPR-17648 will be fixed * @see org.springframework.beans.factory.BeanFactory.getBeanProvider */ -inline fun WebMvcSecurityDsl.provider() : ObjectProvider = context.getBeanProvider() +inline fun WebMvcSecurityDsl.provider(): ObjectProvider = context.getBeanProvider() diff --git a/kofu-webmvc/src/main/kotlin/org/springframework/fu/kofu/webmvc/WebMvcServerDsl.kt b/kofu-webmvc/src/main/kotlin/org/springframework/fu/kofu/webmvc/WebMvcServerDsl.kt index 3f8ec00c8..883e22e03 100644 --- a/kofu-webmvc/src/main/kotlin/org/springframework/fu/kofu/webmvc/WebMvcServerDsl.kt +++ b/kofu-webmvc/src/main/kotlin/org/springframework/fu/kofu/webmvc/WebMvcServerDsl.kt @@ -30,192 +30,196 @@ import org.springframework.web.servlet.function.RouterFunctionDsl * @see org.springframework.fu.kofu.application * @author Sebastien Deleuze */ -@Suppress("DEPRECATION") -open class WebMvcServerDsl(private val init: WebMvcServerDsl.() -> Unit): AbstractDsl() { - - private val serverProperties = ServerProperties() - - private val webMvcProperties = WebMvcProperties() - - private val webProperties = WebProperties() - - private var convertersConfigured: Boolean = false - - /** - * Define the listening port of Spring MVC. - */ - var port: Int = 8080 - - /** - * Define the underlying engine used. - * - * @see tomcat - * @see jetty - * @see undertow - */ - var engine: ConfigurableServletWebServerFactory? = null - - override fun initialize(context: GenericApplicationContext) { - super.initialize(context) - init() - context.registerBean(BeanDefinitionReaderUtils.uniqueBeanName(RouterFunctionDsl::class.java.name, context)) { - org.springframework.web.servlet.function.router { - resources("/**", ClassPathResource("static/")) - } - } - serverProperties.servlet.isRegisterDefaultServlet = false - serverProperties.port = port - if (engine == null) { - engine = tomcat() - } - engine!!.setPort(port) - if (!convertersConfigured) { - StringConverterInitializer().initialize(context) - ResourceConverterInitializer().initialize(context) - } - ServletWebServerInitializer(serverProperties, webMvcProperties, webProperties, engine).initialize(context) - } - - /** - * Configure routes via a [dedicated DSL][RouterFunctionDsl]. - * @sample org.springframework.fu.kofu.samples.webMvcRouter - */ - fun router(routes: (RouterFunctionDsl.() -> Unit)) { - context.registerBean(BeanDefinitionReaderUtils.uniqueBeanName(RouterFunctionDsl::class.java.name, context)) { org.springframework.web.servlet.function.router(routes) } - } - - /** - * Configure converters via a [dedicated DSL][WebMvcConverterDsl]. - */ - fun converters(init: WebMvcConverterDsl.() -> Unit = {}) { - WebMvcConverterDsl(init).initialize(context) - convertersConfigured = true - } - - /** - * Get a reference to the bean by type or type + name with the syntax - * `ref()` or `ref("foo")`. When leveraging Kotlin type inference - * it could be as short as `ref()` or `ref("foo")`. - * TODO Update when SPR-17648 will be fixed - * @param name the name of the bean to retrieve - * @param T type the bean must match, can be an interface or superclass - */ - inline fun RouterFunctionDsl.ref(name: String? = null): T = when (name) { - null -> context.getBean(T::class.java) - else -> context.getBean(name, T::class.java) - } - - /** - * Return an provider for the specified bean, allowing for lazy on-demand retrieval - * of instances, including availability and uniqueness options. - * TODO Update when SPR-17648 will be fixed - * @see org.springframework.beans.factory.BeanFactory.getBeanProvider - */ - inline fun RouterFunctionDsl.provider() : ObjectProvider = context.getBeanProvider() - - /** - * Tomcat engine. - * @see engine - */ - fun tomcat() = TomcatDelegate().invoke() - - /** - * Jetty engine. - * @see engine - */ - fun jetty() = JettyDelegate().invoke() - - /** - * Undertow engine. - * @see engine - */ - fun undertow() = UndertowDelegate().invoke() - - private class TomcatDelegate: () -> ConfigurableServletWebServerFactory { - override fun invoke(): ConfigurableServletWebServerFactory { - return TomcatServletWebServerFactory() - } - } - - private class JettyDelegate: () -> ConfigurableServletWebServerFactory { - override fun invoke(): ConfigurableServletWebServerFactory { - return JettyServletWebServerFactory() - } - } - - private class UndertowDelegate: () -> ConfigurableServletWebServerFactory { - override fun invoke(): ConfigurableServletWebServerFactory { - return UndertowServletWebServerFactory() - } - } - - class WebMvcConverterDsl(private val init: WebMvcConverterDsl.() -> Unit) : AbstractDsl() { - - override fun initialize(context: GenericApplicationContext) { - super.initialize(context) - init() - } - - /** - * Enable [org.springframework.http.converter.StringHttpMessageConverter] - */ - fun string() { - StringConverterInitializer().initialize(context) - } - - /** - * Enable [org.springframework.http.converter.ResourceHttpMessageConverter] and [org.springframework.http.converter.ResourceRegionHttpMessageConverter] - */ - fun resource() { - ResourceConverterInitializer().initialize(context) - } - - /** - * Register an `ObjectMapper` bean and configure a [Jackson](https://github.com/FasterXML/jackson) - * JSON converter on WebMvc server via a [dedicated DSL][JacksonDsl]. - * - * Required dependencies can be retrieve using `org.springframework.boot:spring-boot-starter-json` - * (included by default in `spring-boot-starter-webflux`). - */ - fun jackson(dsl: JacksonDsl.() -> Unit = {}) { - JacksonDsl(dsl).initialize(context) - JacksonJsonConverterInitializer().initialize(context) - } - - /** - * Enable [org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter] - */ - fun form() { - FormConverterInitializer().initialize(context) - } - - /** - * Enable [org.springframework.http.converter.feed.AtomFeedHttpMessageConverter] - */ - fun atom() { - AtomConverterInitializer().initialize(context) - } - - /** - * Enable [org.springframework.http.converter.feed.RssChannelHttpMessageConverter] - */ - fun rss() { - RssConverterInitializer().initialize(context) - } - - /** - * Enable [org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter] - */ - fun kotlinSerialization() { - KotlinSerializationConverterInitializer().initialize(context) - } - } +open class WebMvcServerDsl(private val init: WebMvcServerDsl.() -> Unit) : AbstractDsl() { + + private val serverProperties = ServerProperties() + + private val webMvcProperties = WebMvcProperties() + + private val webProperties = WebProperties() + + private var convertersConfigured: Boolean = false + + /** + * Define the listening port of Spring MVC. + */ + var port: Int = 8080 + + /** + * Define the underlying engine used. + * + * @see tomcat + * @see jetty + * @see undertow + */ + var engine: ConfigurableServletWebServerFactory? = null + + override fun initialize(context: GenericApplicationContext) { + super.initialize(context) + init() + context.registerBean(BeanDefinitionReaderUtils.uniqueBeanName(RouterFunctionDsl::class.java.name, context)) { + org.springframework.web.servlet.function.router { + resources("/**", ClassPathResource("static/")) + } + } + serverProperties.servlet.isRegisterDefaultServlet = false + serverProperties.port = port + if (engine == null) { + engine = tomcat() + } + engine!!.setPort(port) + if (!convertersConfigured) { + StringConverterInitializer().initialize(context) + ResourceConverterInitializer().initialize(context) + } + ServletWebServerInitializer(serverProperties, webMvcProperties, webProperties, engine).initialize(context) + } + + /** + * Configure routes via a [dedicated DSL][RouterFunctionDsl]. + * @sample org.springframework.fu.kofu.samples.webMvcRouter + */ + fun router(routes: (RouterFunctionDsl.() -> Unit)) { + context.registerBean( + BeanDefinitionReaderUtils.uniqueBeanName( + RouterFunctionDsl::class.java.name, + context + ) + ) { org.springframework.web.servlet.function.router(routes) } + } + + /** + * Configure converters via a [dedicated DSL][WebMvcConverterDsl]. + */ + fun converters(init: WebMvcConverterDsl.() -> Unit = {}) { + WebMvcConverterDsl(init).initialize(context) + convertersConfigured = true + } + + /** + * Get a reference to the bean by type or type + name with the syntax + * `ref()` or `ref("foo")`. When leveraging Kotlin type inference + * it could be as short as `ref()` or `ref("foo")`. + * TODO Update when SPR-17648 will be fixed + * @param name the name of the bean to retrieve + * @param T type the bean must match, can be an interface or superclass + */ + inline fun RouterFunctionDsl.ref(name: String? = null): T = when (name) { + null -> context.getBean(T::class.java) + else -> context.getBean(name, T::class.java) + } + + /** + * Return an provider for the specified bean, allowing for lazy on-demand retrieval + * of instances, including availability and uniqueness options. + * TODO Update when SPR-17648 will be fixed + * @see org.springframework.beans.factory.BeanFactory.getBeanProvider + */ + inline fun RouterFunctionDsl.provider(): ObjectProvider = context.getBeanProvider() + + /** + * Tomcat engine. + * @see engine + */ + fun tomcat() = TomcatDelegate().invoke() + + /** + * Jetty engine. + * @see engine + */ + fun jetty() = JettyDelegate().invoke() + + /** + * Undertow engine. + * @see engine + */ + fun undertow() = UndertowDelegate().invoke() + + private class TomcatDelegate : () -> ConfigurableServletWebServerFactory { + override fun invoke(): ConfigurableServletWebServerFactory { + return TomcatServletWebServerFactory() + } + } + + private class JettyDelegate : () -> ConfigurableServletWebServerFactory { + override fun invoke(): ConfigurableServletWebServerFactory { + return JettyServletWebServerFactory() + } + } + + private class UndertowDelegate : () -> ConfigurableServletWebServerFactory { + override fun invoke(): ConfigurableServletWebServerFactory { + return UndertowServletWebServerFactory() + } + } + + class WebMvcConverterDsl(private val init: WebMvcConverterDsl.() -> Unit) : AbstractDsl() { + + override fun initialize(context: GenericApplicationContext) { + super.initialize(context) + init() + } + + /** + * Enable [org.springframework.http.converter.StringHttpMessageConverter] + */ + fun string() { + StringConverterInitializer().initialize(context) + } + + /** + * Enable [org.springframework.http.converter.ResourceHttpMessageConverter] and [org.springframework.http.converter.ResourceRegionHttpMessageConverter] + */ + fun resource() { + ResourceConverterInitializer().initialize(context) + } + + /** + * Register an `ObjectMapper` bean and configure a [Jackson](https://github.com/FasterXML/jackson) + * JSON converter on WebMvc server via a [dedicated DSL][JacksonDsl]. + * + * Required dependencies can be retrieve using `org.springframework.boot:spring-boot-starter-json` + * (included by default in `spring-boot-starter-webflux`). + */ + fun jackson(dsl: JacksonDsl.() -> Unit = {}) { + JacksonDsl(dsl).initialize(context) + JacksonJsonConverterInitializer().initialize(context) + } + + /** + * Enable [org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter] + */ + fun form() { + FormConverterInitializer().initialize(context) + } + + /** + * Enable [org.springframework.http.converter.feed.AtomFeedHttpMessageConverter] + */ + fun atom() { + AtomConverterInitializer().initialize(context) + } + + /** + * Enable [org.springframework.http.converter.feed.RssChannelHttpMessageConverter] + */ + fun rss() { + RssConverterInitializer().initialize(context) + } + + /** + * Enable [org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter] + */ + fun kotlinSerialization() { + KotlinSerializationConverterInitializer().initialize(context) + } + } } /** * Declare a Spring MVC server. * @see WebMvcServerDsl */ -fun ConfigurationDsl.webMvc(dsl: WebMvcServerDsl.() -> Unit = {}) { - WebMvcServerDsl(dsl).initialize(context) +fun ConfigurationDsl.webMvc(dsl: WebMvcServerDsl.() -> Unit = {}) { + WebMvcServerDsl(dsl).initialize(context) }