这是一个更为常见的问题:我使用的是xstream和woodstox,woodstox附带了一个服务提供程序,用于注册com.ctc.wstx.stax.WstxOutputFactory的woodstox jar中的javax.xml.stream.XMLOutputFactory.我想提供自己的javax.xml.stream.XMLOutputFactory,并且在类路径中仍然有woodstox jar.我知道我可以提供我自己的系统属性javax.xml.stream.XMLOutputFactory,但我正试图从我们的开发团队中解脱麻烦,并在我的jar中使用服务文件或者在我的战争中使用META -INF/services文件夹.查看javax.xml.stream.FactoryFinder的代码如何确保我的META-INF/services/javax.xml.stream.XMLOutputFactory文件将是FactoryFinder使用的文件?
我们使用xstream和camel,但找不到将工厂注入XStreamDataFormat的方法
我目前正在尝试获得一个包含Service Factory运行的简单包.
这是我的工厂类:
public class SvcFactory implements ServiceFactory<ServiceB> {
@Override
public ServiceB getService(Bundle bundle,
ServiceRegistration<ServiceB> registration) {
return new ServiceBImpl();
}
@Override
public void ungetService(Bundle bundle, ServiceRegistration<ServiceB> registration,
ServiceB service) {
}
}
Run Code Online (Sandbox Code Playgroud)
这是我应该由工厂创建的服务:
public class ServiceBImpl implements ServiceB {
private ServiceA svcA;
public void setA(ServiceA a) {
svcA = a;
}
}
Run Code Online (Sandbox Code Playgroud)
最后是OSGI-INF/component.xml
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="bundleb.internal.SvcFactory">
<implementation class="bundleb.internal.SvcFactory"/>
<reference bind="setA" cardinality="1..1" interface="bundlea.ServiceA" name="ServiceA" policy="static"/>
<service servicefactory="true">
<provide interface="bundleb.ServiceB"/>
</service>
</scr:component>
Run Code Online (Sandbox Code Playgroud)
如果我在equinox中运行我的测试包(A,B和C),我收到以下错误:
org.osgi.framework.ServiceException: org.eclipse.equinox.internal.ds.FactoryReg.getService() returned a service object that is …Run Code Online (Sandbox Code Playgroud) 我正在使用OSGi声明服务和设置注册OSGi服务
服务工厂="真"
如下.
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="test.Configuration">
<implementation class="test.ConfigurationImpl"/>
<service servicefactory="true">
<provide interface="test.Configuration"/>
</service>
</scr:component>
Run Code Online (Sandbox Code Playgroud)
我试图从另一个包中多次使用该服务.但是,它返回了我相同的服务实例.
这可能会出错?