【问题标题】:Spring BeanCreationException due to NoSuchMethodError in Property class由于属性类中的 NoSuchMethodError 导致 Spring BeanCreationException
【发布时间】:2014-07-21 07:22:56
【问题描述】:

我目前正在尝试启动使用 Maven 构建的应用程序的服务器端;全新安装成功,但随后 tomcat7:run 失败并显示以下 Spring 错误消息

04:21:19,059 [localhost-startStop-1] ERROR org.springframework.web.context.ContextLoader - 
Context initialization failed org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'properties' defined in class path resource [context.xml]: 
Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: 
org.springframework.core.convert.Property.<init>(Ljava/lang/Class;Ljava/lang/reflect/Method;
Ljava/lang/reflect/Method;Ljava/lang/String;)V

context.xml中相关的bean定义如下

<bean id="properties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:server.properties"/>
    <property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>

研究表明,这类错误通常与类路径中不正确的 JAR 版本有关。在这个特定的应用程序中,Spring 版本 3.2.4.RELEASE 依赖项在 Maven pom.xml 中定义,并检查相关 org.springframework.core.convert.Property 类的 API,似乎构造函数 Property(Class objectType, Method readMethod , Method writeMethod, String name) 在这个版本中实际可用。任何想法表示赞赏

【问题讨论】:

  • 能否提供完整的pom文件?
  • 有一个主 pom.xml (10K),其中包含四个模块 pom.xmls,其中一个是提到的服务器模块 (8K)。您希望看到其中的哪些部分?
  • 对。然后尝试构建 .war 并查看 WEB-INF/lib 以查看 Maven 解析的 jar。
  • ...\server\target\server-1.0-SNAPSHOT.war\WEB-INF\lib 包含 spring-*-3.2.4.RELEASE.jar 文件
  • 是的,我不是 Spring 专家,但如果我见过的话,这看起来像是版本不匹配

标签: java spring maven properties classpath


【解决方案1】:

尝试使用-verbose 选项运行您的java。

它显示了从哪个 jar 加载类。

您的 Tomcat 的 bootstrap 类加载器中似乎有一个 spring jar - Spring 的旧版本。

【讨论】:

  • 看来你是对的,java 详细报告:Loaded org.springframework.core.convert.Property from .../server/target/apache-tomcat-maven-plugin/activiti-webapp-explorer2 /WEB-INF/l‌​ib/spring-core-3.1.2.RELEASE.jar。显然根本原因是 Activiti 依赖项都是 5.14 版本;在将这些增加到 5.15 之后,Spring 依赖项上升到 3.2.7.RELEASE,并且报告的 BeanCreationException 不再存在(现在还有另一个与 JDBC 连接相关的 BeanCreationException,但我将单独调查)。感谢您对此的帮助。
  • 我们如何在 eclipse 中添加 -verbose ?我们在哪里添加它?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-05
  • 1970-01-01
  • 1970-01-01
  • 2018-03-08
相关资源
最近更新 更多