4

我有一个基于 Spring MVC (3.0.0.RELEASE) 的应用程序,需要部署到 Oracle Weblogic Server 11gR1。它在 Spring TC Server 上运行良好。当我部署我的应用程序 WAR 文件(通过 STS/Eclipse“服务器”视图或“自动部署”文件夹,或通过网络管理员手动部署)时,我得到以下异常:

    <Feb 3, 2010 9:17:20 AM GMT> <Error> <org.springframework.web.context.ContextLoader> <BEA-000000> <Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/spring/webapp-config.xml]; nested exception is java.lang.ClassCastException: weblogic.xml.jaxp.RegistryDocumentBuilderFactory cannot be cast to javax.xml.parsers.DocumentBuilderFactory
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
 at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
 at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:93)
 at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
 at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:458)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:388)
 at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:192)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
 at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:481)
 at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
 at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
 at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:181)
 at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1801)
 at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3045)
 at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1397)
 at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:460)
 at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
 at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:83)
 at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
 at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.java:200)
 at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:247)
 at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
 at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:83)
 at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
 at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:27)
 at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:1267)
 at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:83)
 at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:409)
 at weblogic.application.internal.SingleModuleDeployment.activate(SingleModuleDeployment.java:39)
 at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:161)
 at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:79)
 at weblogic.deploy.internal.targetserver.BasicDeployment.activate(BasicDeployment.java:184)
 at weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.java:361)
 at weblogic.management.deploy.internal.DeploymentAdapter$1.doActivate(DeploymentAdapter.java:51)
 at weblogic.management.deploy.internal.DeploymentAdapter.activate(DeploymentAdapter.java:196)
 at weblogic.management.deploy.internal.AppTransition$2.transitionApp(AppTransition.java:30)
 at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.java:233)
 at weblogic.management.deploy.internal.ConfiguredDeployments.activate(ConfiguredDeployments.java:169)
 at weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.java:123)
 at weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.java:173)
 at weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.java:89)
 at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)
 at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
 at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

这是由以下原因引起的:

Caused By: java.lang.ClassCastException: weblogic.xml.jaxp.RegistryDocumentBuilderFactory cannot be cast to javax.xml.parsers.DocumentBuilderFactory
 at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
 at org.springframework.beans.factory.xml.DefaultDocumentLoader.createDocumentBuilderFactory(DefaultDocumentLoader.java:89)
 at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:70)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
 at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
 at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:93)
 at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
 at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:458)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:388)
 at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:192)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
 at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:481)
 at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
 at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
 at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:181)
 at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1801)
 at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3045)
 at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1397)
 at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:460)
 at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
 at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:83)
 at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
 at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.java:200)
 at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:247)
 at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
 at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:83)
 at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
 at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:27)
 at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:1267)
 at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:83)
 at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:409)
 at weblogic.application.internal.SingleModuleDeployment.activate(SingleModuleDeployment.java:39)
 at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:161)
 at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:79)
 at weblogic.deploy.internal.targetserver.BasicDeployment.activate(BasicDeployment.java:184)
 at weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.java:361)
 at weblogic.management.deploy.internal.DeploymentAdapter$1.doActivate(DeploymentAdapter.java:51)
 at weblogic.management.deploy.internal.DeploymentAdapter.activate(DeploymentAdapter.java:196)
 at weblogic.management.deploy.internal.AppTransition$2.transitionApp(AppTransition.java:30)
 at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.java:233)
 at weblogic.management.deploy.internal.ConfiguredDeployments.activate(ConfiguredDeployments.java:169)
 at weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.java:123)
 at weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.java:173)
 at weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.java:89)
 at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)
 at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)

现在这是在我已经发现需要设置之后:

<wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>

在 weblogic.xml 中(这解决了我之前的无数问题——类路径完全搞砸了,我遇到了 Spring 的“getBeanDefinitionDefaults(...) 的“NoSuchMethodError”问题,它捆绑在我的 WAR 的 WEB-INF/lib 目录中)。

调查表明,javax.xml.parsers.DocumentBuilderFactory它来自 xml-apis-1.0.b2.jar,它是由 maven 从 commons-digester、dom4j 和 jdom 引入的。简而言之,我需要它来运行我的 Spring 应用程序。

我已经检查(并仔细检查)并且我没有将 weblogic 类与我的战争捆绑在一起,所以我没有在自己的脚下开枪。

我还在 java.net 论坛上看到了这篇文章: http://forums.java.net/jive/thread.jspa?messageID= 216363 - Log4J 解决方法不起作用(我想是因为问题的根源不是 Log4J)和 oracle.com 上的这个错误修复说明(搜索“CR172469”)http://download-llnw.oracle.com/docs/cd/E13222_01/wls/docs81/notes/resolved_sp03.html 这似乎什么也不做。

我不明白的是,我告诉 Weblogic 更喜欢我的 WEB-INF/lib 中的 jar,我需要的 jar 在那里,错误来自 Spring,而不是 Weblogic(即我没有强迫服务器本身使用它无法处理的 jar。)

由于我不确定它的相关性,我推迟了向这个问题添加更多我的 Spring 配置。但是,如果这有帮助,请告诉我,我会添加它。

希望有人可以提供帮助。

注册,安德鲁

4

1 回答 1

8

您的应用程序几乎肯定不应该javax.*在其自身中包含任何类——这些通常由应用服务器处理。如果你这样做,你最终会ClassCastExceptions像这样。

您需要阻止 maven 拖入诸如 之类的东西xml-apis-1.0.b2.jar,它不属于您的应用程序。

如果您解决了这个问题,那么您将无需担心特定于 weblogic 的类加载器设置。

于 2010-02-03T13:37:44.070 回答