【问题标题】:Bundle not resolving while creating Mongodb OSGI Bundle using Amdatu使用 Amdatu 创建 Mongodb OSGI Bundle 时,Bundle 无法解析
【发布时间】:2014-07-18 06:24:03
【问题描述】:

我正在使用org.amdatu.mongo 服务工厂为 Mongodb 创建 OSGi 包,this guide 我正在使用 Gridfs 进行存储。我正在使用 eclipse Bndtool 插件。 为此,我创建了一个名为 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));
}

和实现

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

【问题讨论】:

    标签: java mongodb apache-felix osgi-bundle amdatu


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-25
        • 2012-10-18
        • 2013-03-23
        • 2017-06-11
        • 1970-01-01
        相关资源
        最近更新 更多