Search in sources :

Example 21 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper in project spring-boot by spring-projects.

the class WebSessionIdResolverAutoConfiguration method initializeCookie.

private void initializeCookie(ResponseCookieBuilder builder) {
    Cookie cookie = this.serverProperties.getReactive().getSession().getCookie();
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    map.from(cookie::getDomain).to(builder::domain);
    map.from(cookie::getPath).to(builder::path);
    map.from(cookie::getHttpOnly).to(builder::httpOnly);
    map.from(cookie::getSecure).to(builder::secure);
    map.from(cookie::getMaxAge).to(builder::maxAge);
    map.from(getSameSite(cookie)).to(builder::sameSite);
}
Also used : Cookie(org.springframework.boot.web.server.Cookie) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 22 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper in project spring-boot by spring-projects.

the class MultipartProperties method createMultipartConfig.

/**
 * Create a new {@link MultipartConfigElement} using the properties.
 * @return a new {@link MultipartConfigElement} configured using there properties
 */
public MultipartConfigElement createMultipartConfig() {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    map.from(this.fileSizeThreshold).to(factory::setFileSizeThreshold);
    map.from(this.location).whenHasText().to(factory::setLocation);
    map.from(this.maxRequestSize).to(factory::setMaxRequestSize);
    map.from(this.maxFileSize).to(factory::setMaxFileSize);
    return factory.createMultipartConfig();
}
Also used : MultipartConfigFactory(org.springframework.boot.web.servlet.MultipartConfigFactory) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 23 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper in project spring-boot by spring-projects.

the class RetryTemplateFactory method createRetryTemplate.

RetryTemplate createRetryTemplate(RabbitProperties.Retry properties, RabbitRetryTemplateCustomizer.Target target) {
    PropertyMapper map = PropertyMapper.get();
    RetryTemplate template = new RetryTemplate();
    SimpleRetryPolicy policy = new SimpleRetryPolicy();
    map.from(properties::getMaxAttempts).to(policy::setMaxAttempts);
    template.setRetryPolicy(policy);
    ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
    map.from(properties::getInitialInterval).whenNonNull().as(Duration::toMillis).to(backOffPolicy::setInitialInterval);
    map.from(properties::getMultiplier).to(backOffPolicy::setMultiplier);
    map.from(properties::getMaxInterval).whenNonNull().as(Duration::toMillis).to(backOffPolicy::setMaxInterval);
    template.setBackOffPolicy(backOffPolicy);
    if (this.customizers != null) {
        for (RabbitRetryTemplateCustomizer customizer : this.customizers) {
            customizer.customize(target, template);
        }
    }
    return template;
}
Also used : RetryTemplate(org.springframework.retry.support.RetryTemplate) ExponentialBackOffPolicy(org.springframework.retry.backoff.ExponentialBackOffPolicy) SimpleRetryPolicy(org.springframework.retry.policy.SimpleRetryPolicy) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 24 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper in project spring-boot by spring-projects.

the class RabbitStreamConfiguration method configure.

static EnvironmentBuilder configure(EnvironmentBuilder builder, RabbitProperties properties) {
    builder.lazyInitialization(true);
    RabbitProperties.Stream stream = properties.getStream();
    PropertyMapper mapper = PropertyMapper.get();
    mapper.from(stream.getHost()).to(builder::host);
    mapper.from(stream.getPort()).to(builder::port);
    mapper.from(stream.getUsername()).as(withFallback(properties::getUsername)).whenNonNull().to(builder::username);
    mapper.from(stream.getPassword()).as(withFallback(properties::getPassword)).whenNonNull().to(builder::password);
    return builder;
}
Also used : PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 25 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper in project spring-boot by spring-projects.

the class AbstractConnectionFactoryConfigurer method configure.

/**
 * Configures the given {@code connectionFactory} with sensible defaults.
 * @param connectionFactory connection factory to configure
 */
public final void configure(T connectionFactory) {
    Assert.notNull(connectionFactory, "ConnectionFactory must not be null");
    PropertyMapper map = PropertyMapper.get();
    map.from(this.rabbitProperties::determineAddresses).to(connectionFactory::setAddresses);
    map.from(this.rabbitProperties::getAddressShuffleMode).whenNonNull().to(connectionFactory::setAddressShuffleMode);
    map.from(this.connectionNameStrategy).whenNonNull().to(connectionFactory::setConnectionNameStrategy);
    configure(connectionFactory, this.rabbitProperties);
}
Also used : PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Aggregations

PropertyMapper (org.springframework.boot.context.properties.PropertyMapper)49 Bean (org.springframework.context.annotation.Bean)9 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)8 ServerProperties (org.springframework.boot.autoconfigure.web.ServerProperties)4 DataSize (org.springframework.util.unit.DataSize)4 Duration (java.time.Duration)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 IOException (java.io.IOException)2 Map (java.util.Map)2 AccessLogValve (org.apache.catalina.valves.AccessLogValve)2 AutoConfiguration (org.springframework.boot.autoconfigure.AutoConfiguration)2 EnableAutoConfiguration (org.springframework.boot.autoconfigure.EnableAutoConfiguration)2 Connection (org.springframework.boot.autoconfigure.cassandra.CassandraProperties.Connection)2 Controlconnection (org.springframework.boot.autoconfigure.cassandra.CassandraProperties.Controlconnection)2 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)2 Listener (org.springframework.boot.autoconfigure.kafka.KafkaProperties.Listener)2 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)2 ConsumerAwareRebalanceListener (org.springframework.kafka.listener.ConsumerAwareRebalanceListener)2 StringUtils (org.springframework.util.StringUtils)2