【发布时间】:2015-01-10 19:04:12
【问题描述】:
我正在编写一项服务并观察到@Property,我们也可以在服务内部定义,如下面的代码:
@Component(metatype = true, immediate = true, description = "Demo Service to test")
@Service(value = DemoService.class)
@Properties({
@Property(name = "testprop" , value = "This is Test Property")
})
public class DemoServiceImpl implements DemoService {
@Property(name = "localprop", value = "Local Value")
@Activate
public void activate(ComponentContext ctx)
{
String testprop = (String)ctx.getProperties().get("testprop");
String localprop = (String)ctx.getProperties().get("localprop");
}
}
这两个属性都显示在 felix 控制台中,并可在我的服务中访问。那么是什么造成了在组件内部或外部声明它们的区别。我看到我们不能在组件内部使用@Properties。但不确定是什么让它们在功能上彼此不同以及何时使用它们。
【问题讨论】:
标签: osgi aem apache-felix