Spring beans将重复ID与另一个模式名称空间配置ActiveMQ amq:

时间:2013-05-31 00:46:25

标签: spring activemq

我正在尝试使用Spring配置文件来有选择地声明一个ActiveMQ Broker。我也在使用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>

1 个答案:

答案 0 :(得分:1)

您的stacktrace表示您当前正在通过ContextLoaderListener定义ApplicationContext。

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

<context-param>
  <param-name>spring.profiles.active</param-name>
  <param-value>local</param-value>
</context-param>