Search in sources :

Example 1 with PropertyMapper

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

the class ReleaseInfo method from.

public static ReleaseInfo from(BuildInfoResponse.BuildInfo buildInfo) {
    ReleaseInfo info = new ReleaseInfo();
    PropertyMapper propertyMapper = PropertyMapper.get();
    propertyMapper.from(buildInfo.getName()).to(info::setBuildName);
    propertyMapper.from(buildInfo.getNumber()).to(info::setBuildNumber);
    String[] moduleInfo = StringUtils.delimitedListToStringArray(buildInfo.getModules()[0].getId(), ":");
    propertyMapper.from(moduleInfo[0]).to(info::setGroupId);
    propertyMapper.from(moduleInfo[2]).to(info::setVersion);
    return info;
}
Also used : PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 2 with PropertyMapper

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

the class CorsEndpointProperties method toCorsConfiguration.

public CorsConfiguration toCorsConfiguration() {
    if (CollectionUtils.isEmpty(this.allowedOrigins) && CollectionUtils.isEmpty(this.allowedOriginPatterns)) {
        return null;
    }
    PropertyMapper map = PropertyMapper.get();
    CorsConfiguration configuration = new CorsConfiguration();
    map.from(this::getAllowedOrigins).to(configuration::setAllowedOrigins);
    map.from(this::getAllowedOriginPatterns).to(configuration::setAllowedOriginPatterns);
    map.from(this::getAllowedHeaders).whenNot(CollectionUtils::isEmpty).to(configuration::setAllowedHeaders);
    map.from(this::getAllowedMethods).whenNot(CollectionUtils::isEmpty).to(configuration::setAllowedMethods);
    map.from(this::getExposedHeaders).whenNot(CollectionUtils::isEmpty).to(configuration::setExposedHeaders);
    map.from(this::getMaxAge).whenNonNull().as(Duration::getSeconds).to(configuration::setMaxAge);
    map.from(this::getAllowCredentials).whenNonNull().to(configuration::setAllowCredentials);
    return configuration;
}
Also used : CorsConfiguration(org.springframework.web.cors.CorsConfiguration) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 3 with PropertyMapper

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

the class ConcurrentKafkaListenerContainerFactoryConfigurer method configureListenerFactory.

private void configureListenerFactory(ConcurrentKafkaListenerContainerFactory<Object, Object> factory) {
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    Listener properties = this.properties.getListener();
    map.from(properties::getConcurrency).to(factory::setConcurrency);
    map.from(this.messageConverter).to(factory::setMessageConverter);
    map.from(this.recordFilterStrategy).to(factory::setRecordFilterStrategy);
    map.from(this.replyTemplate).to(factory::setReplyTemplate);
    if (properties.getType().equals(Listener.Type.BATCH)) {
        factory.setBatchListener(true);
        factory.setBatchErrorHandler(this.batchErrorHandler);
    } else {
        factory.setErrorHandler(this.errorHandler);
    }
    map.from(this.commonErrorHandler).to(factory::setCommonErrorHandler);
    map.from(this.afterRollbackProcessor).to(factory::setAfterRollbackProcessor);
    map.from(this.recordInterceptor).to(factory::setRecordInterceptor);
}
Also used : ConsumerAwareRebalanceListener(org.springframework.kafka.listener.ConsumerAwareRebalanceListener) Listener(org.springframework.boot.autoconfigure.kafka.KafkaProperties.Listener) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 4 with PropertyMapper

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

the class ConcurrentKafkaListenerContainerFactoryConfigurer method configureContainer.

private void configureContainer(ContainerProperties container) {
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    Listener properties = this.properties.getListener();
    map.from(properties::getAckMode).to(container::setAckMode);
    map.from(properties::getClientId).to(container::setClientId);
    map.from(properties::getAckCount).to(container::setAckCount);
    map.from(properties::getAckTime).as(Duration::toMillis).to(container::setAckTime);
    map.from(properties::getPollTimeout).as(Duration::toMillis).to(container::setPollTimeout);
    map.from(properties::getNoPollThreshold).to(container::setNoPollThreshold);
    map.from(properties.getIdleBetweenPolls()).as(Duration::toMillis).to(container::setIdleBetweenPolls);
    map.from(properties::getIdleEventInterval).as(Duration::toMillis).to(container::setIdleEventInterval);
    map.from(properties::getIdlePartitionEventInterval).as(Duration::toMillis).to(container::setIdlePartitionEventInterval);
    map.from(properties::getMonitorInterval).as(Duration::getSeconds).as(Number::intValue).to(container::setMonitorInterval);
    map.from(properties::getLogContainerConfig).to(container::setLogContainerConfig);
    map.from(properties::isOnlyLogRecordMetadata).to(container::setOnlyLogRecordMetadata);
    map.from(properties::isMissingTopicsFatal).to(container::setMissingTopicsFatal);
    map.from(properties::isImmediateStop).to(container::setStopImmediate);
    map.from(this.transactionManager).to(container::setTransactionManager);
    map.from(this.rebalanceListener).to(container::setConsumerRebalanceListener);
}
Also used : ConsumerAwareRebalanceListener(org.springframework.kafka.listener.ConsumerAwareRebalanceListener) Listener(org.springframework.boot.autoconfigure.kafka.KafkaProperties.Listener) Duration(java.time.Duration) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 5 with PropertyMapper

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

the class CassandraAutoConfiguration method mapConfig.

private Config mapConfig(CassandraProperties properties) {
    CassandraDriverOptions options = new CassandraDriverOptions();
    PropertyMapper map = PropertyMapper.get();
    map.from(properties.getSessionName()).whenHasText().to((sessionName) -> options.add(DefaultDriverOption.SESSION_NAME, sessionName));
    map.from(properties::getUsername).whenNonNull().to((username) -> options.add(DefaultDriverOption.AUTH_PROVIDER_USER_NAME, username).add(DefaultDriverOption.AUTH_PROVIDER_PASSWORD, properties.getPassword()));
    map.from(properties::getCompression).whenNonNull().to((compression) -> options.add(DefaultDriverOption.PROTOCOL_COMPRESSION, compression));
    mapConnectionOptions(properties, options);
    mapPoolingOptions(properties, options);
    mapRequestOptions(properties, options);
    mapControlConnectionOptions(properties, options);
    map.from(mapContactPoints(properties)).to((contactPoints) -> options.add(DefaultDriverOption.CONTACT_POINTS, contactPoints));
    map.from(properties.getLocalDatacenter()).to((localDatacenter) -> options.add(DefaultDriverOption.LOAD_BALANCING_LOCAL_DATACENTER, localDatacenter));
    return options.build();
}
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