gpt4 book ai didi

Spring 上下文 :component-scan casting exception

转载 作者:行者123 更新时间:2023-12-01 11:39:25 25 4
gpt4 key购买 nike

我有一个奇怪的错误,我在互联网上搜索了很多。我不明白为什么会出现此错误。我在 spring jira 上找到了关于该错误的一些解释。我在 applicationContext.xml 中有 context:component-scan 并且在 com.sow.webservices 包中定义了 5 个包。但是,当我添加包含 Controller 类的 Controller 包时,我会抛出

Error occured processing XML '[Ljava.lang.String; cannot be cast to java.lang.String'. See Error Log for more details

这是组件扫描:

<context:component-scan base-package="com.sow.webservices.aop, 
com.sow.webservices.exceptions,
com.sow.webservices.models,
com.sow.webservices.services,
com.sow.webservices.controller">

我想向您展示整个异常跟踪。感谢您的帮助。

!ENTRY org.springframework.ide.eclipse.beans.core 1 0 2014-04-11 18:07:39.996
!MESSAGE Error occured processing '/SOW_WS/src/main/webapp/WEB-INF/applicationContext.xml'
!STACK 0
java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.lang.String
at org.springframework.context.annotation.AnnotationBeanNameGenerator.determineBeanNameFromAnnotation(AnnotationBeanNameGenerator.java:92)
at org.springframework.context.annotation.AnnotationBeanNameGenerator.generateBeanName(AnnotationBeanNameGenerator.java:70)
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:247)
at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:85)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)
at org.springframework.ide.eclipse.beans.core.internal.model.namespaces.DelegatingNamespaceHandlerResolver$ElementTrackingNamespaceHandler.parse(DelegatingNamespaceHandlerResolver.java:177)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1427)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ErrorSuppressingBeanDefinitionParserDelegate.parseCustomElement(BeansConfig.java:1400)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1417)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:187)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ToolingFriendlyBeanDefinitionDocumentReader.doRegisterBeanDefinitions(BeansConfig.java:1330)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:110)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:494)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.registerBeanDefinitions(BeansConfig.java:402)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.loadBeanDefinitions(BeansConfig.java:388)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:445)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

即使 xml 抛出此异常,我也可以运行我的应用程序,但是当我删除 com.sow.webservices.controller 时,它不再显示有错误标志,但它给出了 404 错误。由于我在组件扫描方面遇到麻烦,LocaleChangeInterceptor 无法正常工作,我无法将我的应用程序国际化

最佳答案

检查您的 Controller ,如果其中一个 Controller 使用注解@ControllerAdvice,请尝试将其注释掉,奇怪的是错误消失了。怪异的!!!!

关于 Spring 上下文 :component-scan casting exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23016418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com