当我给localhost时,port可以正常工作,但不能使用uri属性工作。以下是获取错误。我将启用存储库属性设置为true
我正在使用mongorepositroy将对象保存到mogodb
Caused by: java.lang.IllegalStateException: Invalid mongo configuration, either uri or host/port/credentials must be specified
at org.springframework.boot.autoconfigure.mongo.MongoProperties.createNetworkMongoClient(MongoProperties.java:237) ~[spring-boot-autoconfigure-1.5.12.RELEASE.jar!/:1.5.12.RELEASE]
at org.springframework.boot.autoconfigure.mongo.MongoProperties.createMongoClient(MongoProperties.java:208) ~[spring-boot-autoconfigure-1.5.12.RELEASE.jar!/:1.5.12.RELEASE]
at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.mongo(MongoAutoConfiguration.java:73) ~[spring-boot-autoconfigure-1.5.12.RELEASE.jar!/:1.5.12.RELEASE]
at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration$$EnhancerBySpringCGLIB$$5c5a8ad9.CGLIB$mongo$0(<generated>) ~[spring-boot-autoconfigure-1.5.12.RELEASE.jar!/:1.5.12.RELEASE]
at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration$$EnhancerBySpringCGLIB$$5c5a8ad9$$FastClassBySpringCGLIB$$8f9aa5d8.invoke(<generated>) ~[spring-boot-autoconfigure-1.5.12.RELEASE.jar!/:1.5.12.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration$$EnhancerBySpringCGLIB$$5c5a8ad9.mongo(<generated>) ~[spring-boot-autoconfigure-1.5.12.RELEASE.jar!/:1.5.12.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
... 89 common frames omitted
这是application.yml
spring:
data:
mongodb:
uri: mongodb://server1:27017,server2:27017,server3:27017/dbname
使用以下pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.12.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>