use*_*241 1 spring spring-mvc mongodb
错误:
2016年2月19日00:00:16.731严重[localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException:创建名称为'personService'的bean时出错:注入自动装配依赖项失败;嵌套的异常是org.springframework.beans.factory.BeanCreationException:无法自动连线字段:私有org.springframework.data.mongodb.core.MongoTemplate com.test.app.service.PersonService.mongoTemplate; 嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建在ServletContext资源[/WEB-INF/mvc-dispatcher-servlet.xml]中定义的名称为'mongoTemplate'的bean时出错。嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化bean类[org。[springframework.data.mongodb.core.MongoTemplate]:构造函数抛出异常;嵌套异常是java.lang.NoSuchMethodError:org.springframework.core.convert.support.ConversionServiceFactory.createDefaultConversionService()Lorg / springframework / core / convert / support / GenericConversionService;
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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-3.0.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.2.xsd">
<context:component-scan base-package="com.test.app" />
<mvc:annotation-driven/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<!-- Factory bean that creates the Mongo instance -->
<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
<property name="host" value="localhost" />
</bean>
<!-- MongoTemplate for connecting and querying the documents in the database -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongo" ref="mongo" />
<constructor-arg name="databaseName" value="test" />
</bean>
<!-- Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean id="personController" class="com.test.app.controller.PersonController" />
<bean id="personService" class="com.test.app.service.PersonService" />
<bean id="person" class="com.test.app.model.Person" />
</beans>Run Code Online (Sandbox Code Playgroud)
我看到许多有关此错误的信息,但没有解决此问题的答案。
小智 5
spring-core的版本需要与spring-data的版本匹配。以下是我的部分pom.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
<!-- Spring data mongodb -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.8.2.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
它是固定的。
| 归档时间: |
|
| 查看次数: |
8914 次 |
| 最近记录: |