【问题标题】:No declaration can be found for element 'osgi:reference'找不到元素“osgi:reference”的声明
【发布时间】:2018-09-29 05:37:51
【问题描述】:

我在 Apache ServiceMix 6.1.0 上运行。

我在foo项目的pom.xml中有以下依赖:

<dependencies>
    <dependency>
        <groupId>com.proj.bar</groupId>
        <artifactId>foo</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>3.2.14.RELEASE</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-parent</artifactId>
        <version>2.15.3</version>
        <type>pom</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.compendium</artifactId>
        <version>4.2.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>2.15.3</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

我的 spring core-context.xml 中有以下内容:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:osgi="http://www.springframework.org/schema/osgi"
   xmlns:camel="http://camel.apache.org/schema/spring"
   xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
   http://camel.apache.org/schema/spring
   http://camel.apache.org/schema/spring/camel-spring.xsd
   http://www.springframework.org/schema/osgi-compendium
   http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd">

    <!-- OSGI SERVICE REGISTER -->
    <osgi:service id="configService" interface="com.proj.bar.foo.service.interfaces.IConfigService" ref="configServiceBean">
        <service-properties>
            <entry key="osgi.jndi.service.name" value="ConfigService" />
        </service-properties>
    </osgi:service>
</beans>

我的 spring foo-context.xml 中有以下内容

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:osgi="http://www.springframework.org/schema/osgi"
   xmlns:camel="http://camel.apache.org/schema/spring"
   xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
   http://camel.apache.org/schema/spring
   http://camel.apache.org/schema/spring/camel-spring.xsd
   http://www.springframework.org/schema/osgi-compendium
   http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd">

    <!-- SERVICE REFERENCES -->
    <osgi:reference id="configService"
                interface="com.proj.bar.foo.service.interfaces.IConfigService"
                filter="(osgi.jndi.service.name=ConfigService)"/>
</beans>

我收到以下异常:

2015-12-16 11:24:20,550 | ERROR | ExtenderThread-8 | ContextLoaderListener            | 94 - org.springframework.osgi.extender - 1.2.1 | Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=foo, config=osgibundle:/META-INF/spring/*.xml))
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 16 in XML document from URL [bundle://248.29:0/META-INF/spring/foo-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'osgi:reference'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:397)[87:org.apache.servicemix.bundles.spring-beans:3.2.14.RELEASE_1]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)[87:org.apache.servicemix.bundles.spring-beans:3.2.14.RELEASE_1]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)[87:org.apache.servicemix.bundles.spring-beans:3.2.14.RELEASE_1]
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)[87:org.apache.servicemix.bundles.spring-beans:3.2.14.RELEASE_1]
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)[87:org.apache.servicemix.bundles.spring-beans:3.2.14.RELEASE_1]
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)[87:org.apache.servicemix.bundles.spring-beans:3.2.14.RELEASE_1]
at org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:164)[93:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:136)[93:org.springframework.osgi.core:1.2.1]
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)[89:org.apache.servicemix.bundles.spring-context:3.2.14.RELEASE_1]
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:539)[89:org.apache.servicemix.bundles.spring-context:3.2.14.RELEASE_1]
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$800(AbstractDelegatedExecutionApplicationContext.java:69)[93:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$3.run(AbstractDelegatedExecutionApplicationContext.java:269)[93:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)[93:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.startRefresh(AbstractDelegatedExecutionApplicationContext.java:247)[93:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:214)[94:org.springframework.osgi.extender:1.2.1]
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:169)[94:org.springframework.osgi.extender:1.2.1]
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:175)[93:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:716)[94:org.springframework.osgi.extender:1.2.1]
at java.lang.Thread.run(Thread.java:744)[:1.7.0_45]
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'osgi:reference'.
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.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.handleStartElement(Unknown Source)[:]
at org.apache.xerces.impl.xs.XMLSchemaValidator.emptyElement(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)[87:org.apache.servicemix.bundles.spring-beans:3.2.14.RELEASE_1]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:389)[87:org.apache.servicemix.bundles.spring-beans:3.2.14.RELEASE_1]
... 18 more

我完全不知道我能做些什么来解决这个问题。 它似乎在我的核心项目中运行良好,但我没有做任何不同的事情。它似乎无法识别 osgi:reference 标记,但命名空间定义应该是正确的。

有人知道是什么原因造成的吗?

提前谢谢!

【问题讨论】:

  • 你应该在 OSGi 中使用蓝图 - spring-dm 已经死了,并且不能真正工作。
  • 我的一位同事让它为他的项目工作,只是我看不出我在这里做错了什么。我猜它是某个地方的依赖问题。

标签: spring apache-camel apache-servicemix


【解决方案1】:

您的xsi:schemaLocation 缺少对osgi 的引用,它只有osgi-compendium

你还需要添加这个:

http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd

【讨论】:

  • 我有springframework.org/schema/osgi。而camel-osgi应该足够了,而不是spring-osgi
  • 在您提供的示例 XML 中,您指定了 xmlns:osgi="http://www.springframework.org/schema/osgi",但您没有在架构位置声明命名空间,例如xsi:schemaLocation="http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd"
  • 哦,对了,让我试试。奇怪的是,我的同事和我的声明完全相同,但它对他有用。一旦我尝试这个,我会报告
猜你喜欢
  • 2012-07-02
  • 2012-11-28
  • 2012-09-14
  • 2016-09-09
  • 1970-01-01
  • 1970-01-01
  • 2021-09-07
  • 2013-10-23
相关资源
最近更新 更多