【发布时间】:2015-11-24 07:40:46
【问题描述】:
我正在尝试使用 osgi @reference 创建一个地图对象,即)将以下类注册为工厂,并将依赖项作为 Hashmap 对象。我的意图是使用应该创建哈希图的工厂创建一个对象。当我试图将其注册为工厂状态时不满意。是否可以通过以下方法创建地图对象?如果没有,任何人都可以让我知道我做错了什么吗?或者为什么我们不应该这样做?因为 Map 是一个接口。
@Component(name = "ExampleComponentFactoryServiceProvider1", factory = "example.factory.provider1")
@Service
public class ExampleComponentFactoryServiceProvider1 implements ExampleFactoryService {
@Reference(name = "MapObject", bind = "createMap", unbind = "disolveMapObject", referenceInterface = Map.class)
private Map<String, String> testMap = null;
@Activate
public void activate(Map<String, String> props) {
System.out.println("Activated 1 !!!!!");
}
public void createMap(Map<String, String> aMap) {
this.testMap = aMap;
System.out.println("Map created !! " + testMap);
}
public void disolveMapObject(Map<String, String> aMap) {
this.testMap = null;
}
@Override
public void start() {
System.out.println("Started 1 !!!!");
}
@Override
public void stop() {
System.out.println("Stopped 1 !!!!");
}
}
【问题讨论】:
标签: java osgi apache-felix