2013-02-07 19 views
1

此基础代码是否能够成功在使命令scopeA:在shell访问的测试:菲利克斯列出OSGI包处于活动状态,但勾勾Shell命令不可访问(依赖关系)

package com.A; 

import org.apache.felix.ipojo.annotations.Component; 
import org.apache.felix.ipojo.annotations.Instantiate; 
import org.apache.felix.ipojo.annotations.Provides; 
import org.apache.felix.ipojo.annotations.Requires; 
import org.apache.felix.ipojo.annotations.ServiceProperty; 
import org.apache.felix.service.command.Descriptor; 

@Component(immediate = true) 
@Instantiate 
@Provides(specifications = Commands.class) 
public final class Commands { 

    @ServiceProperty(name = "osgi.command.scope", value = "scopeA") 
    String scope; 

    @ServiceProperty(name = "osgi.command.function", value = "{}") 
    String[] function = new String[] { 
      "test" 
    }; 

    @Descriptor("Example") 
    public void test() { 
     System.out.println("hello"); 
    } 
} 

但是,如果我添加一个构造函数,依赖于另一个OSGI组件,它不再可访问命令,“帮助”不会列出它。然而,该包仍然可以加载到活动状态。

package com.A; 

import org.apache.felix.ipojo.annotations.Component; 
import org.apache.felix.ipojo.annotations.Instantiate; 
import org.apache.felix.ipojo.annotations.Provides; 
import org.apache.felix.ipojo.annotations.Requires; 
import org.apache.felix.ipojo.annotations.ServiceProperty; 
import org.apache.felix.service.command.Descriptor; 

import com.B; 

@Component(immediate = true) 
@Instantiate 
@Provides(specifications = Commands.class) 
public final class Commands { 

    public Commands(@Requires B b) { 
    } 

    @ServiceProperty(name = "osgi.command.scope", value = "scopeA") 
    String scope; 

    @ServiceProperty(name = "osgi.command.function", value = "{}") 
    String[] function = new String[] { 
      "test" 
    }; 

    @Descriptor("Example") 
    public void test() { 
     System.out.println("hello"); 
    } 
} 

B的内容很简单:

import org.apache.felix.ipojo.annotations.Component; 
import org.apache.felix.ipojo.annotations.Instantiate; 
import org.apache.felix.ipojo.annotations.Provides; 

@Component(immediate = true) 
@Instantiate 
@Provides 
final class B { 
} 

为什么命令不再列出任何想法?提示找到有关状态的更多信息,以便我可以更好地调试此问题?

+0

B服务是否真正发布?您可以使用命令“inspect cap service [id]”来检查,其中[id]应该是包含组件B的bundle的ID。 –

回答

1

问题是,命令需要@Requires在一个字段而不是在构造函数中。

@Requires 
B b; 

构造函数也必须删除。

这是因为gogo有调用组件的特殊方法。

相关问题