While configuring the Mongo DB with Spring MVC (5.2.9.RELEASE) and deploying it to Tomcat 9.5 as WAR file it is giving me the follow error:
Below is the stacktrace:
Many thanks, I was able to resolve that, but now it is showing me error Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: DEFAULT with the pom entry:<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.7</version>
</dependency>
<!-- Spring data mongodb -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
Below is my configuration:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">
<mongo:mongo-client id="mongoClient" host="127.0.0.1" port="27017" />
<mongo:db-factory id="mongoDbFactory" dbname="mydocs" mongo-ref="mongoClient"/>
<!-- <mongo:db-factory id="mongoDbFactory" host="127.0.0.1" port="27017" dbname="mydocs" username="" password=""/> -->
<mongo:mapping-converter id="converter" db-factory-ref="mongoDbFactory"/>
<bean name="gridFsTemplate"
class="org.springframework.data.mongodb.gridfs.GridFsTemplate">
<constructor-arg ref="mongoDbFactory" />
<constructor-arg ref="converter" />
</bean>
And I am using the mongodb dependency as follows:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.7</version>
</dependency>
<!-- Spring data mongodb -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
Please advice how to resolve the issue
Error message states mongo-ref is not allowed in mongo:db-factory. So use <mongo:db-factory mongo-client-ref="…" />
instead since mongo-ref
has been replaced in 3.x. Read more at Removed XML Namespace Elements & Attributes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.