我在本地计算机上将Spring Boot 2.0.4与Couchbase服务器(企业版5.5)一起用作Docker容器。我有一个扩展了AbstractCouchbaseConfiguration
的配置类,在其中提供了沙发基准群集/存储桶详细信息。
存储库接口用@N1qlPrimaryIndexed
和@ViewIndexed(designDoc = "person", viewName = "all")
注释,而我的application.properties文件具有spring.data.couchbase.auto-index=true
据我了解,Spring Boot应该能够自动创建主索引和视图。
这是我的配置类
public class CouchbaseConfig extends AbstractCouchbaseConfiguration {
@Value("${couchbase_host}")
private String hostname;
@Value("${couchbase_bucket}")
private String bucket;
@Override
@Bean(name = BeanNames.COUCHBASE_CLUSTER_INFO)
public ClusterInfo couchbaseClusterInfo() throws Exception {
return couchbaseCluster().authenticate("Administrator","password").clusterManager().info();
}
@Bean
public Cluster cluster() {
return CouchbaseCluster.create(getEnvironment(),hostname);
}
@Override
@Bean(destroyMethod = "close", name = BeanNames.COUCHBASE_BUCKET)
public Bucket couchbaseClient() throws Exception {
return couchbaseCluster().openBucket(getBucketName());
}
@Override
protected List<String> getBootstrapHosts() {
return Collections.singletonList(hostname);
}
@Override
protected String getBucketName() {
return bucket;
}
@Override
protected String getBucketPassword() {
return "password";
}
@Override
protected CouchbaseEnvironment getEnvironment() {
CouchbaseEnvironment environment = DefaultCouchbaseEnvironment.builder()
.connectTimeout(25000)
.queryTimeout(75000)
.kvTimeout(5000)
.socketConnectTimeout(40000)
.build();
return environment;
}
当我根据上述配置启动我的应用时,
2018-08-10 19:47:31.653 INFO 29198 --- [ main] i.InspectionsAggregateServiceApplication : No active profile set, falling back to default profiles: default
2018-08-10 19:47:31.697 INFO 29198 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@757acd7b: startup date [Fri Aug 10 19:47:31 CDT 2018]; root of context hierarchy
2018-08-10 19:47:32.283 INFO 29198 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'requestContextFilter' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration; factoryMethodName=requestContextFilter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.class]] with [Root bean: class [org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=requestContextFilter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2018-08-10 19:47:32.463 INFO 29198 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2018-08-10 19:47:32.836 INFO 29198 --- [ main] o.s.b.w.e.t.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-08-10 19:47:32.856 INFO 29198 --- [ main] o.a.c.c.StandardService : Starting service [Tomcat]
2018-08-10 19:47:32.856 INFO 29198 --- [ main] o.a.c.c.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.32
2018-08-10 19:47:32.859 INFO 29198 --- [ost-startStop-1] o.a.c.c.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/lakshmananraman/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2018-08-10 19:47:32.965 INFO 29198 --- [ost-startStop-1] o.a.c.c.C.[.[.[/] : Initializing Spring embedded WebApplicationContext
2018-08-10 19:47:32.966 INFO 29198 --- [ost-startStop-1] o.s.w.c.ContextLoader : Root WebApplicationContext: initialization completed in 1272 ms
2018-08-10 19:47:33.215 INFO 29198 --- [ost-startStop-1] o.s.b.w.s.ServletRegistrationBean : Servlet com.ge.trans.rc360.inspection.config.JerseyConfig mapped to [/api/*]
2018-08-10 19:47:33.218 INFO 29198 --- [ost-startStop-1] o.s.b.w.s.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-08-10 19:47:33.221 INFO 29198 --- [ost-startStop-1] o.s.b.w.s.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-08-10 19:47:33.221 INFO 29198 --- [ost-startStop-1] o.s.b.w.s.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-08-10 19:47:33.221 INFO 29198 --- [ost-startStop-1] o.s.b.w.s.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-08-10 19:47:33.221 INFO 29198 --- [ost-startStop-1] o.s.b.w.s.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-08-10 19:47:33.444 INFO 29198 --- [ main] c.c.c.c.CouchbaseCore : CouchbaseEnvironment: {sslEnabled=false, sslKeystoreFile='null', sslTruststoreFile='null', sslKeystorePassword=false, sslTruststorePassword=false, sslKeystore=null, sslTruststore=null, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=8, computationPoolSize=8, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=12, queryServiceEndpoints=12, searchServiceEndpoints=12, configPollInterval=2500, configPollFloorInterval=50, ioPool=NioEventLoopGroup, kvIoPool=null, viewIoPool=null, searchIoPool=null, queryIoPool=null, coreScheduler=CoreScheduler, memcachedHashingStrategy=DefaultMemcachedHashingStrategy, eventBus=DefaultEventBus, packageNameAndVersion=couchbase-java-client/2.5.9 (git: 2.5.9, core: 1.5.9), retryStrategy=BestEffort, maxRequestLifetime=75000, retryDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=100, upper=100000}, reconnectDelay=ExponentialDelay{growBy 1.0 MILLISECONDS, powers of 2; lower=32, upper=4096}, observeIntervalDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=10, upper=100000}, keepAliveInterval=30000, continuousKeepAliveEnabled=true, keepAliveErrorThreshold=4, keepAliveTimeout=2500, autoreleaseAfter=2000, bufferPoolingEnabled=true, tcpNodelayEnabled=true, mutationTokensEnabled=false, socketConnectTimeout=40000, callbacksOnIoPool=false, disconnectTimeout=25000, requestBufferWaitStrategy=com.couchbase.client.core.env.DefaultCoreEnvironment$2@6b760460, certAuthEnabled=false, coreSendHook=null, forceSaslPlain=false, queryTimeout=75000, viewTimeout=75000, searchTimeout=75000, analyticsTimeout=75000, kvTimeout=5000, connectTimeout=25000, dnsSrvEnabled=false}
2018-08-10 19:47:33.701 INFO 29198 --- [ cb-io-1-1] c.c.c.c.n.Node : Connected to Node 127.0.0.1/localhost
2018-08-10 19:47:33.750 INFO 29198 --- [ cb-io-1-1] c.c.c.c.n.Node : Disconnected from Node 127.0.0.1/localhost
2018-08-10 19:47:34.146 INFO 29198 --- [ cb-io-1-2] c.c.c.c.n.Node : Connected to Node 127.0.0.1/localhost
2018-08-10 19:47:34.208 INFO 29198 --- [-computations-4] c.c.c.c.c.ConfigurationProvider : Opened bucket person
2018-08-10 19:47:34.459 WARN 29198 --- [ main] c.c.c.c.e.CoreEnvironment : More than 1 Couchbase Environments found (2), this can have severe impact on performance and stability. Reuse environments!
2018-08-10 19:47:34.460 INFO 29198 --- [ main] c.c.c.c.CouchbaseCore : CouchbaseEnvironment: {sslEnabled=false, sslKeystoreFile='null', sslTruststoreFile='null', sslKeystorePassword=false, sslTruststorePassword=false, sslKeystore=null, sslTruststore=null, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=8, computationPoolSize=8, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=12, queryServiceEndpoints=12, searchServiceEndpoints=12, configPollInterval=2500, configPollFloorInterval=50, ioPool=NioEventLoopGroup, kvIoPool=null, viewIoPool=null, searchIoPool=null, queryIoPool=null, coreScheduler=CoreScheduler, memcachedHashingStrategy=DefaultMemcachedHashingStrategy, eventBus=DefaultEventBus, packageNameAndVersion=couchbase-java-client/2.5.9 (git: 2.5.9, core: 1.5.9), retryStrategy=BestEffort, maxRequestLifetime=75000, retryDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=100, upper=100000}, reconnectDelay=ExponentialDelay{growBy 1.0 MILLISECONDS, powers of 2; lower=32, upper=4096}, observeIntervalDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=10, upper=100000}, keepAliveInterval=30000, continuousKeepAliveEnabled=true, keepAliveErrorThreshold=4, keepAliveTimeout=2500, autoreleaseAfter=2000, bufferPoolingEnabled=true, tcpNodelayEnabled=true, mutationTokensEnabled=false, socketConnectTimeout=40000, callbacksOnIoPool=false, disconnectTimeout=25000, requestBufferWaitStrategy=com.couchbase.client.core.env.DefaultCoreEnvironment$2@1a87b51, certAuthEnabled=false, coreSendHook=null, forceSaslPlain=false, queryTimeout=75000, viewTimeout=75000, searchTimeout=75000, analyticsTimeout=75000, kvTimeout=5000, connectTimeout=25000, dnsSrvEnabled=false}
2018-08-10 19:47:34.569 INFO 29198 --- [ main] o.s.w.s.h.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-10 19:47:34.681 INFO 29198 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@757acd7b: startup date [Fri Aug 10 19:47:31 CDT 2018]; root of context hierarchy
2018-08-10 19:47:34.734 INFO 29198 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-08-10 19:47:34.735 INFO 29198 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-08-10 19:47:34.754 INFO 29198 --- [ main] o.s.w.s.h.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-10 19:47:34.755 INFO 29198 --- [ main] o.s.w.s.h.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-10 19:47:34.922 INFO 29198 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-08-10 19:47:34.955 INFO 29198 --- [ main] o.s.b.w.e.t.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
我注意到它连接到节点并断开与节点的连接,并显示警告,发现存在多个不便的环境。 尽管存储桶是打开的,但是spring不会创建视图和索引,并且我的应用程序失败。
Caused by:
org.springframework.dao.InvalidDataAccessResourceUsageException: View
person/all does not exist.; nested exception is
com.couchbase.client.java.error.ViewDoesNotExistException: View
person/all does not exist.
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: com.couchbase.client.java.document.json.JsonObject.class
2018-08-10 19:47:35.115 INFO 29198 --- [ main] ConfigServletWebServerApplicationContext : Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@757acd7b: startup date [Fri Aug 10 19:47:31 CDT 2018]; root of context hierarchy
2018-08-10 19:47:35.116 INFO 29198 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2018-08-10 19:47:35.123 INFO 29198 --- [ main] c.c.c.c.c.ConfigurationProvider : Closed bucket person
2018-08-10 19:47:35.123 INFO 29198 --- [ cb-io-1-2] c.c.c.c.n.Node : Disconnected from Node 127.0.0.1/localhost
请帮助我理解为什么spring会找到两个沙发床环境,并且未按预期创建主索引和视图。
答案 0 :(得分:2)
再次重新阅读文档后,我在IndexManager
方法上添加了覆盖,并在覆盖其他方法之后,正确配置了环境。