简体   繁体   English

使用Amdatu创建Mongodb OSGI Bundle时,Bundle无法解析

[英]Bundle not resolving while creating Mongodb OSGI Bundle using Amdatu

I am creating OSGi bundle for Mongodb using org.amdatu.mongo service factory following this guide I am using Gridfs for the storage purpose. 我按照本指南使用org.amdatu.mongo服务工厂为Mongodb创建OSGi捆绑软件,我将Gridfs用于存储目的。 I am using eclipse Bndtool plugin. 我正在使用Eclipse Bndtool插件。 for this purpose I have created an Interface Named AgendaMongo and an Activator and Implementation class here is code for both 为此,我创建了一个名为AgendaMongo的接口,以及一个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));
}

and the implementation 和实施

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();

}


}

Now on Running and Testing it using apache Felix Gogo compiler I am getting the following exception. 现在,使用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/

我已经解决了这个问题,根据amdatu,我们需要mongo jar作为运行时所需的依赖项,因为我需要在需求osgi.wiring.package添加此mongo jar,主要是因为缺少依赖项包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM