Error creating bean with name 'xxxcontroller': Unsatisfied dependency expressed 'mongotemplete'
原本写test时编译成功了,网上没找到解决办法,最终发现原因是xml文件引入依赖的问题
解决办法:如果你和我一样引入了这三个依赖(默认最新版本),删掉其他关于MongoDb的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</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-web</artifactId>
</dependency>
原因:不同版本依赖互相冲突。spring-boot-sarter-data-mongodb已经包含了mongo-java-driver。
删掉的其他版本举例:
<depenency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.0.4</version>
</dependency>