Java org.springframework.beans.factory.annotation.InjectionMetadata.needsRefresh

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24674760/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 14:02:04  来源:igfitidea点击:

org.springframework.beans.factory.annotation.InjectionMetadata.needsRefresh

javaspringhibernatespring-mvcconfiguration

提问by Braham Shakti

I am getting a problem while running spring hibernate project for

我在运行 spring hibernate 项目时遇到问题

java.lang.NoSuchMethodError: org.springframework.beans.factory.annotation.InjectionMetadata.needsRefresh(Lorg/springframework/beans/factory/annotation/InjectionMetadata;Ljava/lang/Class;)Z
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:383)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:332)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:830)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:493)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:449)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

I have included following jarsin my project

jars在我的项目中包含了以下内容

commons-dbcp2-2.0.1.jar
commons-pool2-2.2.jar
hibernate3.jar
hibernate-annotations.jar
hibernate-commons-annotations-4.0.4.Final.jar
hibernate-core-4.3.5.Final.jar
hibernate-entitymanager.jar
hibernate-validator.jar
javax.persistence.jar
jta.jar
mysql-connector-java-5.1.7-bin.jar
spring-aop-4.0.5.RELEASE.jar
spring-aspects-4.0.5.RELEASE.jar
spring-beans-4.0.5.RELEASE.jar
spring-build-src-4.0.5.RELEASE.jar
spring-context-4.0.5.RELEASE.jar
spring-context-support-4.0.5.RELEASE.jar
spring-core-4.0.5.RELEASE.jar
spring-expression-4.0.5.RELEASE.jar
spring-framework-bom-4.0.5.RELEASE.jar
spring-instrument-4.0.5.RELEASE.jar
spring-instrument-tomcat-4.0.5.RELEASE.jar
spring-jdbc-4.0.5.RELEASE.jar
spring-jms-4.0.5.RELEASE.jar
spring-messaging-4.0.5.RELEASE.jar
spring-orm-4.0.5.RELEASE.jar
spring-oxm-4.0.5.RELEASE.jar
spring-test-4.0.5.RELEASE.jar
spring-tx-4.0.5.RELEASE.jar
spring-web-4.0.5.RELEASE.jar
spring-webmvc-4.0.5.RELEASE.jar
spring-webmvc-portlet-4.0.5.RELEASE.jar
spring-websocket-4.0.5.RELEASE.jar

My servlet-context.xmllooks like

我的servlet-context.xml样子

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
                    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
                    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
                    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
                    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jsp" />
</beans:bean>

<beans:bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <beans:property name="basename" value="classpath:messages" />
    <beans:property name="defaultEncoding" value="UTF-8" />
</beans:bean>

<beans:bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
    p:location="/WEB-INF/jdbc.properties" />

<beans:bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
    destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
    p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}">
</beans:bean>

<beans:bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <beans:property name="dataSource" ref="dataSource" />
    <beans:property name="configLocation">
        <beans:value>classpath:hibernate.cfg.xml</beans:value>
    </beans:property>
    <beans:property name="hibernateProperties">
        <beans:props>
            <beans:prop key="hibernate.dialect">${jdbc.dialect}</beans:prop>
            <beans:prop key="hibernate.show_sql">true</beans:prop>
        </beans:props>
    </beans:property>
</beans:bean>
<tx:annotation-driven />


<context:component-scan base-package="com.spring.webapp" />

</beans:beans>

Some one on stackoverflow has asked for checking same version of jars file. Please help me to resolve this error as I have already same version of jars included in project

stackoverflow 上的某个人要求检查相同版本的 jars 文件。请帮我解决这个错误,因为我已经在项目中包含了相同版本的 jars

回答by Vlad Mihalcea

The needsRefresh()method was added in Spring 4.0.x and so it can't be found in the 3.0.x version.

needsRefresh()方法是在 Spring 4.0.x 中添加的,因此在 3.0.x 版本中找不到。

You need to run:

你需要运行:

mvn dependency:tree

and look for a Spring core/beans jar having the 3.x.x version. If you have multiple versions of the same lib, the class-loader can pick the first one it found, and the behavior could become chaotic.

并寻找具有 3.xx 版本的 Spring 核心/beans jar。如果您有同一个库的多个版本,类加载器可以选择它找到的第一个,并且行为可能会变得混乱。

Also, you have both hibernate3.jarand hibernate-core-4.3.5.Final.jar, so make sure you get rid of old versions.

此外,您同时拥有hibernate3.jarhibernate-core-4.3.5.Final.jar,因此请确保删除旧版本。

回答by user598656

Unconfirmed but I've seen this error also from what appeared to be a Spring 3.2.5 to 3.2.8 issue; i.e. after uplift of all Spring dependencies to 3.2.8 (exceptSpring Security, remaining on 3.2.5) the problem was resolved.

未经证实,但我也从似乎是 Spring 3.2.5 到 3.2.8 的问题中看到了这个错误;即将所有 Spring 依赖项提升到 3.2.8(Spring Security除外,保留在 3.2.5 上)后,问题得到解决。

回答by Mithun Debnath

I was working in eclips spring mvc project.there my application was running well with pivotal tc server but I was getting this error when ever I was trying to run it using tomcat appache.I realized that this is because JRE with the project 1.6 and tomcat was 1.8.I upgrade the JRE to 1.8 and I was able to remove the error.

我在 eclips spring mvc 项目中工作。那里我的应用程序在关键 tc 服务器上运行良好,但是当我尝试使用 tomcat appache 运行它时出现此错误。我意识到这是因为项目 1.6 和 tomcat 的 JRE是 1.8。我将 JRE 升级到 1.8,我能够消除错误。

回答by Raj Kumar Mishra

install below maven dependency

在 maven 依赖项下安装

        <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>