0

我正在尝试使用 Spring 配置文件来选择性地声明 ActiveMQ 代理。我也在使用 amq:broker 命名空间。但是,我不断收到“原因:org.xml.sax.SAXParseException;lineNumber:179;columnNumber:129;cvc-id.2:ID 值‘messageCentreBroker’多次出现。” 上下文初始化错误。

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:amq="http://activemq.apache.org/schema/core"         
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jms="http://www.springframework.org/schema/jms"
    xsi:schemaLocation="
              http://www.springframework.org/schema/beans 
              http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
              http://www.springframework.org/schema/jms 
              http://www.springframework.org/schema/jms/spring-jms-3.0.xsd 
              http://activemq.apache.org/schema/core 
              http://activemq.apache.org/schema/core/activemq-core.xsd">

    <beans profile="dev">   
        <amq:broker id="messageCentreBroker" brokerName="messageCentreBroker" useJmx="true" persistent="true" advisorySupport="true">   
                ... other stuff particular to "dev" profile ...
        </amq:broker>
    </beans>
    <beans profile="local">
        <amq:broker id="messageCentreBroker" brokerName="messageCentreBroker" useJmx="true" persistent="true" advisorySupport="true">   
                ... other stuff particular to "local" profile...
        </amq:broker>   
    </beans>    
</beans>

这也是完整的堆栈跟踪

2013-05-31 10:34:55,807 [DEBUG] org.springframework.beans.factory.xml.PluggableSchemaResolver: Found XML schema [http://activemq.apache.org/schema/core/activemq-core.xsd] in classpath: activemq.xsd
2013-05-31 10:34:56,128 [ERROR] org.springframework.web.context.ContextLoader: Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 179 in XML document from class path resource [au/gov/dha/messagecentre/messagecentre-jms.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 179; columnNumber: 129; cvc-id.2: There are multiple occurrences of ID value 'messageCentreBroker'.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
    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:174)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:527)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:441)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: org.xml.sax.SAXParseException; lineNumber: 179; columnNumber: 129; cvc-id.2: There are multiple occurrences of ID value 'messageCentreBroker'.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.processOneAttribute(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.processAttributes(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
    ... 21 more

我的 web.xml 当前正在选择配置文件,例如(没有占位符)

<servlet>
    <servlet-name>messagecentre</servlet-name>
    <init-param>
        <param-name>spring.profiles.active</param-name>
        <param-value>local</param-value>
    </init-param>
</servlet>
4

1 回答 1

1

您的堆栈跟踪表明您当前正在通过 ContextLoaderListener 定义 ApplicationContext。

ContextLoaderListener 不使用init-parambut context-param。所以尝试在你的 web.xml 中使用

<context-param>
  <param-name>spring.profiles.active</param-name>
  <param-value>local</param-value>
</context-param>
于 2013-05-31T07:15:53.473 回答