gpt4 book ai didi

java - 使用 Amdatu 创建 Mongodb OSGI Bundle 时 bundle 未解析

转载 作者:行者123 更新时间:2023-12-01 12:44:38 55 4
gpt4 key购买 nike

我正在使用 org.amdatu.mongo 服务工厂为 Mongodb 创建 OSGi bundle ,如下 this guide我使用 Gridfs 进行存储。我正在使用 eclipse Bndtool 插件。为此,我创建了一个名为 AgendaMongo 的接口(interface)和一个 ActivatorImplementation 类,这里是两者的代码

public class Activator extends DependencyActivatorBase {

@Override
public void init(BundleContext arg0, DependencyManager manager)
throws Exception {
manager.add(createComponent()
.setInterface(AgendaMongo.class.getName(), null)
.setImplementation(Gridfs_Mongodb.class));
}

以及实现

public class Gridfs_Mongodb implements AgendaMongo{
GridFSInputFile gfsinput=null;
private volatile MongoDBService mongoservice;
public Object store_in_db() {
GridFSInputFile gfsinput=null;
try {
GridFS gfsHandler;
gfsHandler = new GridFS(mongoservice.getDB(), "rest_data");// database
File uri = new File("f:\\get1.jpg"); // name and
gfsinput = gfsHandler.createFile(uri);
gfsinput.saveChunks(1000);
gfsinput.setFilename("new file");
gfsinput.save();
System.out.println(gfsinput.getId());
//save_filepath("file",gfsinput.getId());
Object get_id = gfsinput.getId();//get_filename();
System.out.println(getData(get_id));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return gfsinput.getId();
}

/*
* Retrieving the file
*/
public InputStream getData(Object file_id) {
GridFS gfsPhoto = new GridFS(mongoservice.getDB(), "rest_data");
GridFSDBFile dataOutput = gfsPhoto.findOne((ObjectId) file_id);
DBCursor cursor = gfsPhoto.getFileList();
while (cursor.hasNext()) {
System.out.println(cursor.next());
}
System.out.println(dataOutput);
return dataOutput.getInputStream();

}


}

现在使用 apache Felix Gogo 编译器运行和测试它,我收到以下异常。

! could not resolve the bundles
! Failed to start bundle agenda.mongodb.mongo_gfs-0.0.0, exception Unresolved constraint in bundle agenda.mongodb.mongo_gfs [7]: Unable to resolve 7.0: missing requirement [7.0] osgi.wiring.package; (&(osgi.wiring.package=com.mongodb)(version>=2.11.0)(!(version>=3.0.0)))

最佳答案

您还需要安装标准 Mongo 驱动程序包:http://central.maven.org/maven2/org/mongodb/mongo-java-driver/

关于java - 使用 Amdatu 创建 Mongodb OSGI Bundle 时 bundle 未解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24818458/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com