意外异常从 class 路径资源解析 XML 文档
Unexpected exception parsing XML document from class path resource
我在初始化 spring 上下文时遇到此异常。
我可以确认我只使用了一个 spring 版本,即 5.3.3。
当我删除时,
<context:annotation-config />
<context:component-scan base-package="com" />
从 xml 然后没有与此相关的错误。
同样的 applicationContext.xml 文件正在另一个分支中工作。
2021-07-13 05:05:01,832 INFO [stdout] (ServerService Thread Pool -- 121) DEBUG [4] (07/13/21 06:05:01:832): Startup Bean Invocation: 0 failed
2021-07-13 05:05:01,833 INFO [stdout] (ServerService Thread Pool -- 121) EXCEPTION [3] (07/13/21 06:05:01:833): org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [applicationContext.xml]; nested exception is org.springframework.beans.FatalBeanException: Class [org.springframework.context.config.ContextNamespaceHandler] for namespace [http://www.springframework.org/schema/context] does not implement the [org.springframework.beans.factory.xml.NamespaceHandler] interface: Exception occurred invoking Server Startup Bean
2021-07-13 05:05:01,835 ERROR [stderr] (ServerService Thread Pool -- 121) org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [applicationContext.xml]; nested exception is org.springframework.beans.FatalBeanException: Class [org.springframework.context.config.ContextNamespaceHandler] for namespace [http://www.springframework.org/schema/context] does not implement the [org.springframework.beans.factory.xml.NamespaceHandler] interface
2021-07-13 05:05:01,835 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:417)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:338)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:257)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:128)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractRefreshableApplicationContext.__refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:40002)
2021-07-13 05:05:01,837 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:676)
2021-07-13 05:05:01,837 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:558)
2021-07-13 05:05:01,837 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:41010)
2021-07-13 05:05:01,837 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
2021-07-13 05:05:01,837 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
2021-07-13 05:05:01,837 ERROR [stderr] (ServerService Thread Pool -- 121) at com.prescient.stnmm.server.beans.BeanAccess.<init>(BeanAccess.java:124)
在我看来,即使您只使用一个版本,我也认为存在内部混淆依赖版本...这导致依赖之间存在困难和冲突。
确保检查了本地所有依赖项的版本。无论如何,我仍在研究更好的答案。
下面是我的应用的耳朵结构
'sample.jar'
'firstWar'
'secondWar'
在 sample.jar 文件中,我定义了正在从 'secondWar.war' 项目初始化的 bean。这两个项目即 sample.jar 和 'secondWar.war' 具有相同的依赖性,即 'spring-webmvc' 这导致了混乱。从 'secondWar.war' 中删除了此依赖项,它现在可以正常工作了**
我在初始化 spring 上下文时遇到此异常。
我可以确认我只使用了一个 spring 版本,即 5.3.3。
当我删除时,
<context:annotation-config />
<context:component-scan base-package="com" />
从 xml 然后没有与此相关的错误。 同样的 applicationContext.xml 文件正在另一个分支中工作。
2021-07-13 05:05:01,832 INFO [stdout] (ServerService Thread Pool -- 121) DEBUG [4] (07/13/21 06:05:01:832): Startup Bean Invocation: 0 failed
2021-07-13 05:05:01,833 INFO [stdout] (ServerService Thread Pool -- 121) EXCEPTION [3] (07/13/21 06:05:01:833): org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [applicationContext.xml]; nested exception is org.springframework.beans.FatalBeanException: Class [org.springframework.context.config.ContextNamespaceHandler] for namespace [http://www.springframework.org/schema/context] does not implement the [org.springframework.beans.factory.xml.NamespaceHandler] interface: Exception occurred invoking Server Startup Bean
2021-07-13 05:05:01,835 ERROR [stderr] (ServerService Thread Pool -- 121) org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [applicationContext.xml]; nested exception is org.springframework.beans.FatalBeanException: Class [org.springframework.context.config.ContextNamespaceHandler] for namespace [http://www.springframework.org/schema/context] does not implement the [org.springframework.beans.factory.xml.NamespaceHandler] interface
2021-07-13 05:05:01,835 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:417)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:338)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:257)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:128)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractRefreshableApplicationContext.__refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
2021-07-13 05:05:01,836 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:40002)
2021-07-13 05:05:01,837 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:676)
2021-07-13 05:05:01,837 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:558)
2021-07-13 05:05:01,837 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:41010)
2021-07-13 05:05:01,837 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
2021-07-13 05:05:01,837 ERROR [stderr] (ServerService Thread Pool -- 121) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
2021-07-13 05:05:01,837 ERROR [stderr] (ServerService Thread Pool -- 121) at com.prescient.stnmm.server.beans.BeanAccess.<init>(BeanAccess.java:124)
在我看来,即使您只使用一个版本,我也认为存在内部混淆依赖版本...这导致依赖之间存在困难和冲突。
确保检查了本地所有依赖项的版本。无论如何,我仍在研究更好的答案。
下面是我的应用的耳朵结构 'sample.jar' 'firstWar' 'secondWar'
在 sample.jar 文件中,我定义了正在从 'secondWar.war' 项目初始化的 bean。这两个项目即 sample.jar 和 'secondWar.war' 具有相同的依赖性,即 'spring-webmvc' 这导致了混乱。从 'secondWar.war' 中删除了此依赖项,它现在可以正常工作了**