Spring MVC 项目无法发布和运行...消息:无法自省注释
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26629489/
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
Spring MVC project not able to publish and run... Message: Failed to introspect annotations
提问by Ashok Krishnamoorthy
I have a Spring MVC application(4.1.1-Release version). When I try to publish and Run on Server I am getting the below mentioned error.
我有一个 Spring MVC 应用程序(4.1.1-Release 版本)。当我尝试在服务器上发布和运行时,出现以下错误。
Additional Information
附加信息
- Using Spring Tool Suite 3.6.1
- Spring version 4.1.1-RELEASE
- It is a maven project
- It does not have any compilation error
- when i do mvn clean install , the build is successful
- 使用 Spring Tool Suite 3.6.1
- Spring 版本 4.1.1-RELEASE
- 这是一个maven项目
- 它没有任何编译错误
- 当我执行 mvn clean install 时,构建成功
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'homeController' defined in file [/home/abc/Tools/sts-bundle/pivotal-tc-server-developer-3.0.0.RELEASE/base-instance/wtpwebapps/project-name/WEB-INF/classes/com/abc/project/HomeController.class]: Post-processing failed of bean type [class com.abc.project.HomeController] failed; nested exception is java.lang.IllegalStateException: Failed to introspect annotations: public java.lang.String com.abc.project.HomeController.hello() at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:929) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:725) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4760) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5184) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714) at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581) at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1686) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) 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:745) Caused by: java.lang.IllegalStateException: Failed to introspect annotations: public java.lang.String com.abc.project.HomeController.hello() at org.springframework.core.annotation.AnnotatedElementUtils.process(AnnotatedElementUtils.java:166) at org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes(AnnotatedElementUtils.java:91) at org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes(AnnotatedElementUtils.java:85) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.findAutowiredAnnotation(AutowiredAnnotationBeanPostProcessor.java:416) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.buildAutowiringMetadata(AutowiredAnnotationBeanPostProcessor.java:388) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.findAutowiringMetadata(AutowiredAnnotationBeanPostProcessor.java:358) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(AutowiredAnnotationBeanPostProcessor.java:233) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:924) ... 25 more Caused by: java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.isInJavaLangAnnotationPackage(Ljava/lang/annotation/Annotation;)Z at org.springframework.core.annotation.AnnotatedElementUtils.doProcess(AnnotatedElementUtils.java:208) at org.springframework.core.annotation.AnnotatedElementUtils.process(AnnotatedElementUtils.java:162) ... 32 more Oct 29, 2014 5:00:21 PM org.apache.catalina.core.StandardContext listenerStart SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'homeController' defined in file [/home/abc/Tools/sts-bundle/pivotal-tc-server-developer-3.0.0.RELEASE/base-instance/wtpwebapps/project-name/WEB-INF/classes/com/abc/project/HomeController.class]: Post-processing failed of bean type [class com.abc.project.HomeController] failed; nested exception is java.lang.IllegalStateException: Failed to introspect annotations: public java.lang.String com.abc.project.HomeController.hello() at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:929) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:725) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4760) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5184) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714) at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581) at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1686) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) 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:745) Caused by: java.lang.IllegalStateException: Failed to introspect annotations: public java.lang.String com.abc.project.HomeController.hello() at org.springframework.core.annotation.AnnotatedElementUtils.process(AnnotatedElementUtils.java:166) at org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes(AnnotatedElementUtils.java:91) at org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes(AnnotatedElementUtils.java:85) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.findAutowiredAnnotation(AutowiredAnnotationBeanPostProcessor.java:416) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.buildAutowiringMetadata(AutowiredAnnotationBeanPostProcessor.java:388) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.findAutowiringMetadata(AutowiredAnnotationBeanPostProcessor.java:358) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(AutowiredAnnotationBeanPostProcessor.java:233) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:924) ... 25 more Caused by: java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.isInJavaLangAnnotationPackage(Ljava/lang/annotation/Annotation;)Z at org.springframework.core.annotation.AnnotatedElementUtils.doProcess(AnnotatedElementUtils.java:208) at org.springframework.core.annotation.AnnotatedElementUtils.process(AnnotatedElementUtils.java:162) ... 32 more
org.springframework.beans.factory.BeanCreationException:在文件 [/home/abc/Tools/sts-bundle/pivotal-tc-server-developer-3.0.0.RELEASE/base-instance 中定义名称为“homeController”的 bean 创建时出错/wtpwebapps/project-name/WEB-INF/classes/com/abc/project/HomeController.class]:bean类型[class com.abc.project.HomeController]的后处理失败;嵌套异常是 java.lang.IllegalStateException: Failed to introspect annotations: public java.lang.String com.abc.project.HomeController.hello() at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java: 929) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java: 异常将上下文初始化事件发送到类 org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException 的侦听器实例:在文件 [/home/abc/Tools/sts- 中定义名称为“homeController”的 bean 创建时出错bundle/pivotal-tc-server-developer-3.0.0.RELEASE/base-instance/wtpwebapps/project-name/WEB-INF/classes/com/abc/project/HomeController.class]:bean类型后处理失败[class com.abc.project.HomeController] 失败;嵌套异常是 java.lang.IllegalStateException: Failed to introspect annotations: public java.lang.String com.abc.project.HomeController.hello() at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:第 929 章
回答by pmartin8
I had this error when I was importing via @import a class that wasn't deployed on the server. Unfortunatly, the stack doesn't tell you what class is missing, but you can figure it out with removing them one by one and restart your app.
当我通过@import 导入一个没有部署在服务器上的类时,我遇到了这个错误。不幸的是,堆栈并没有告诉您缺少哪个类,但是您可以通过将它们一一删除并重新启动应用程序来弄清楚。
Now, why wouldn't the class be deployed on the server if the project actually compiles?
现在,如果项目实际编译,为什么不将类部署在服务器上?
EDIT: I found out I had the problem when the import is using a class that is on the classpath via a Maven dependency. I also had this dependency (the project) checked out in Eclipse. In this case, it seems Eclipse will deploy the project checked out instead of the build from the repository. It won't look at the external dependency of this project.
编辑:我发现当导入通过 Maven 依赖项使用类路径上的类时我遇到了问题。我还在 Eclipse 中检出了这个依赖项(项目)。在这种情况下,Eclipse 似乎将部署签出的项目,而不是从存储库中构建。它不会查看这个项目的外部依赖。
The solution: Close all external dependency projects in Eclipse to make sure that you actually deploy the version from Maven repository.
解决方案:关闭 Eclipse 中的所有外部依赖项目,以确保您实际部署了来自 Maven 存储库的版本。
回答by Vinod Chandak
You might be missing
你可能错过了
<context:component-scan base-package="org.example">
in your applicationContext.xml file OR
在您的 applicationContext.xml 文件中或
@ComponentScan("com.example")
annotation if you are doing code based configuration.
如果您正在进行基于代码的配置,则注释。
回答by Ashok Krishnamoorthy
I had old versions of spring libraries in my WEB-INF/lib. I deleted everything in lib folder and tried building and publishing. It worked.
我的 WEB-INF/lib 中有旧版本的 spring 库。我删除了 lib 文件夹中的所有内容并尝试构建和发布。有效。
Thanks.
谢谢。
回答by M. Deinum
Judging from the stacktrace you are mixing different versions of Spring. java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.isInJavaLangAnnotationPackage(Ljava/lang/annotation/Annotation;)is the indicator for that.
从堆栈跟踪来看,您正在混合不同版本的 Spring。java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.isInJavaLangAnnotationPackage(Ljava/lang/annotation/Annotation;)是指标。
Check your dependencies and make sure that you don't pull in conflicting versions.
检查您的依赖项并确保您没有引入冲突的版本。
General rule of thumb, never mix jars of different versions of a framework (in this case Spring but same applies to for instance Hibernate).
一般的经验法则,永远不要混合框架的不同版本的 jar(在这种情况下是 Spring,但同样适用于例如 Hibernate)。

![asp.net-mvc Create 上的“Id 字段是必需的”验证消息;Id 未设置为 [必需]](/res/img/loading.gif)