Java 为什么 .NoSuchMethodError: org.springframework.core.convert.converter.ConverterRegistry.addConverter
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20438807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
why .NoSuchMethodError: org.springframework.core.convert.converter.ConverterRegistry.addConverter
提问by Amar
My maven project uses spring, hibernate. I get "no such method error". I believe it is due to some conflict in version in dependencies but dont know what. The build is successful. But during "NetBeans: Deploying on GlassFish Server 4.0" (i use the run button in Netbeans), i get below error which i have tried hard to eliminate without success. Any assistance is appreciated...
我的 maven 项目使用 spring、hibernate。我得到“没有这样的方法错误”。我相信这是由于依赖项中的版本存在一些冲突,但不知道是什么。构建成功。但是在“NetBeans:在 GlassFish Server 4.0 上部署”期间(我使用 Netbeans 中的运行按钮),我遇到了以下错误,我已努力尝试消除但没有成功。任何帮助表示赞赏...
failed on GlassFish Server 4.0
Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: org.springframework.core.convert.converter.ConverterRegistry.addConverter(Ljava/lang/Class;Ljava/lang/Class;Lorg/springframework/core/convert/converter/Converter;)V.
Below i my pom.xml
下面我是我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>Spring3HibernateMaven</groupId>
<artifactId>AttestationSpring3HibernateMaven</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<description></description>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- === -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.7.Final</version>
</dependency>
<!-- === -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
<exclusions>
<exclusion>
<artifactId>hibernate-commons-annotations</artifactId>
<groupId>org.hibernate</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.1.Final</version>
</dependency>
<!-- === -->
<!--
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
<type>jar</type>
</dependency>
-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.10</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>20030825.184428</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>20030825.183949</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
<type>jar</type>
</dependency>
</dependencies>
<properties>
<org.springframework.version>3.2.1.RELEASE
</org.springframework.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<netbeans.hint.deploy.server>gfv4ee7</netbeans.hint.deploy.server>
</properties>
<name>AttestationSpring3HibernateMaven</name>
</project>
Below is my spring-servlet.xml where datasource, sessionfactory configurations are made..
下面是我的 spring-servlet.xml,其中进行了数据源、会话工厂配置。
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="org.attestation.entities" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<!--======
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
-->
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
采纳答案by Amar
The problem originated when i adapted the project from a working maven+spring+hibernate project. In a zealous attempt, i updated the pom.xml with all the latest versions of dependencies which i think led to the problem. But why it leads to problem, i am not sure. But for now, i have reverted to the original working (but older) versions of dependencies in pom.xml and everything has started working fine. Thanks for your assistance & efforts.
当我从一个工作中的 maven+spring+hibernate 项目改编该项目时,问题就出现了。在一次热心的尝试中,我使用我认为导致问题的所有最新版本的依赖项更新了 pom.xml。但为什么会导致问题,我不确定。但是现在,我已经恢复到 pom.xml 中依赖项的原始工作(但较旧)版本,并且一切都开始正常工作。感谢您的帮助和努力。
回答by Gerard Ribas
Check if all jars of Spring Framework has the same version. I had this problem before and it occurs because one dependency of spring framework was in other version number.
检查 Spring Framework 的所有 jars 是否具有相同的版本。我之前遇到过这个问题,这是因为 spring 框架的一个依赖项在其他版本号中。
You can check the conflicts using maven console:
您可以使用 Maven 控制台检查冲突:
mvn dependency:tree -Dverbose
回答by Kaster
If text file encoding of your project is "Cp1252", change it to "UTF-8".
如果您项目的文本文件编码为“Cp1252”,请将其更改为“UTF-8”。
回答by Steve
Just had one of our junior developers here had a very similar error with a spring boot app. Turns out IntelliJ was messed up, we quit IntelliJ, deleted the ".idea" folder within the project, and re-opened. Things worked just fine after that.
刚刚我们的一位初级开发人员在使用 spring boot 应用程序时遇到了非常相似的错误。结果发现 IntelliJ 搞砸了,我们退出 IntelliJ,删除项目中的“.idea”文件夹,然后重新打开。之后一切都很好。
It seems that there must have been some caching that IntelliJ was doing to either store libraries or resolve dependencies. And somehow that cache got corrupted.
似乎 IntelliJ 正在做一些缓存来存储库或解析依赖项。不知何故,该缓存已损坏。
I know that the original post mentioned NetBeans (not IntelliJ) but I figured leaving this answer here might help. I don't have enough reputation to comment.
我知道最初的帖子提到了 NetBeans(不是 IntelliJ),但我认为将这个答案留在这里可能会有所帮助。我没有足够的声誉发表评论。