1. 程式人生 > >osgi服務報錯以及相應的解決方法

osgi服務報錯以及相應的解決方法

自己在專案中配置相關的OSGI服務,然後不能正常啟動,首先是看容器的日誌,

日誌報錯如下

Could not start bundlemvn:com.gzydt.license/com.gzydt.license.sign.service/1.0.0 in feature(s)license-sign-0.0.0: Unresolved constraint in bundlecom.gzydt.license.sign.service [239]: Unable to resolve 239.0: missingrequirement [239.0] osgi.wiring.package;(osgi.wiring.package=com.gzydt.license.sign.persist)

像碰到這種說在等待自己的元件的相關依賴的錯誤,一般可能有兩種情況,第一,在依賴包中(pom)檔案中沒有加要依賴的包的範圍,一般是提供範圍為provide。如下就可以

<dependency>
		 <groupId>com.gzydt.license</groupId>
			<artifactId>com.gzydt.license.base.persist</artifactId>
			<version>1.0.0</version>
			<!--這個範圍一定要提供,不然的話會依賴其他的包  -->
			<scope>provided</scope>
		</dependency>
		<dependency>
			 <groupId>com.gzydt.license</groupId>
			<artifactId>com.gzydt.license.base.service</artifactId>
			<version>1.0.0</version>
			<!--這個範圍一定要提供,不然的話會依賴其他的包  -->
			<scope>provided</scope>
		</dependency>
第二種情況就是要依賴的元件沒有想外提供服務,導致他不能使用該元件的服務,

修改如下則可以

<Export-Package>
	com.gzydt.license.base.persist,
	com.gzydt.license.base.persist.entity,
	org.apache.commons.dbcp2
</Export-Package>


第二種錯誤:

org.osgi.service.blueprint.container.ComponentDefinitionException:Unresolved ref/idref to component: licenseService


首先找到是在哪個元件中報這個錯誤的,然後到相應的buleprint.xml檔案中去修改相應的服務

然後修改為正確的服務即可