|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
|
* Copyright 2012-2021 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.
|
|
|
|
@ -27,18 +27,24 @@ import com.couchbase.client.core.env.SecurityConfig;
|
|
|
|
|
import com.couchbase.client.core.env.TimeoutConfig;
|
|
|
|
|
import com.couchbase.client.java.Cluster;
|
|
|
|
|
import com.couchbase.client.java.ClusterOptions;
|
|
|
|
|
import com.couchbase.client.java.codec.JacksonJsonSerializer;
|
|
|
|
|
import com.couchbase.client.java.env.ClusterEnvironment;
|
|
|
|
|
import com.couchbase.client.java.env.ClusterEnvironment.Builder;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.ObjectProvider;
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|
|
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
|
|
|
|
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties.Timeouts;
|
|
|
|
|
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.core.Ordered;
|
|
|
|
|
import org.springframework.util.ResourceUtils;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -50,6 +56,7 @@ import org.springframework.util.ResourceUtils;
|
|
|
|
|
* @since 1.4.0
|
|
|
|
|
*/
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
|
@AutoConfigureAfter(JacksonAutoConfiguration.class)
|
|
|
|
|
@ConditionalOnClass(Cluster.class)
|
|
|
|
|
@ConditionalOnProperty("spring.couchbase.connection-string")
|
|
|
|
|
@EnableConfigurationProperties(CouchbaseProperties.class)
|
|
|
|
@ -111,4 +118,37 @@ public class CouchbaseAutoConfiguration {
|
|
|
|
|
return store;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
|
@ConditionalOnClass(ObjectMapper.class)
|
|
|
|
|
static class JacksonConfiguration {
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
@ConditionalOnSingleCandidate(ObjectMapper.class)
|
|
|
|
|
ClusterEnvironmentBuilderCustomizer cluster(ObjectMapper objectMapper) {
|
|
|
|
|
return new JacksonClusterEnvironmentBuilderCustomizer(objectMapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final class JacksonClusterEnvironmentBuilderCustomizer
|
|
|
|
|
implements ClusterEnvironmentBuilderCustomizer, Ordered {
|
|
|
|
|
|
|
|
|
|
private final ObjectMapper objectMapper;
|
|
|
|
|
|
|
|
|
|
private JacksonClusterEnvironmentBuilderCustomizer(ObjectMapper objectMapper) {
|
|
|
|
|
this.objectMapper = objectMapper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void customize(Builder builder) {
|
|
|
|
|
builder.jsonSerializer(JacksonJsonSerializer.create(this.objectMapper));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getOrder() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|