gpt4 book ai didi

web-applications - 如何在 Tapestry 中使用 OSGi 服务

转载 作者:行者123 更新时间:2023-12-01 03:54:40 24 4
gpt4 key购买 nike

我有我的 Tapestry Web 应用程序,它为某些数据集提供了完整的 CRUD 功能。
到目前为止,我一直在使用模拟来开发和测试它。

但是,我现在需要用 OSGi 服务(使用 Felix 运行)替换该模拟。

我的主要问题/问题是:

  • 我是否需要将 OSGi 服务注入(inject)到我的 Tapestry 应用程序中,如果需要,该怎么做?
  • 假设它是注入(inject)的,有没有关于如何使用它的实践?我应该调用这些方法或类似的任何特殊方法吗?
  • 在我调用了我需要的方法之后,我是否需要对它做一些事情,还是自动完成?
  • 我需要担心HttpService (看了一些吐槽,但不是很明白)

  • 为您提供一些背景信息,这就是我现在的做法
    public class MyPage {
    ...
    @Inject
    private MyDao dao;
    ...
    @Property
    private List<Entry> entries;
    ...
    void onPrepareForRender() {
    ...
    this.entries = this.dao.getAll()
    ...
    }
    ...
    }

    我想要替换 MyDao dao使用提供相同功能的 OSGi 服务,因此我可以在 onPrepareForRender 中使用它方法,例如。

    我可以放心地假设与该服务关联的 OSGi 包已经在运行。

    应用程序的其余部分作为 OSGi 应用程序制作。
    我在 pom.xml 中添加/更改了一些东西(maven-bundle-plugin,按照 http://www.javabeat.net/2011/11/writing-an-osgi-web-application/ 中的说明添加了一些 list 条目)。

    但是,它仍然不起作用。

    顺便说一句,我正在尝试将我的 WAR 转换为 WAB。

    先感谢您 :)

    编辑:从 WAR 转换和部署到 WAB 时出现问题

    当我将我的网络应用程序打包为 war东西工作正常。但是,当我将其打包为 bundle ,并尝试在 GlassFish 中部署它,我收到以下错误消息:

    Error occurred during deployment: There is no installed container capable of handling this application admin-war. Please see server.log for more details.



    当我转到 server.log 时,它是这样说的:
    [#|2013-08-27T17:11:57.600+0200|INFO|glassfish3.1.2|org.glassfish.admingui|_ThreadID=28;_ThreadName=Thread-2;|uploadFileName=admin-war-2.01-SNAPSHOT.jar|#]

    [#|2013-08-27T17:11:57.920+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:\glassfish3\glassfish\domains\domain1\applications\admin-war recorded it as a pre-existing stale file|#]

    [#|2013-08-27T17:11:57.939+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=33;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:\glassfish3\glassfish\domains\domain1\applications\admin-war recorded it as a pre-existing stale file|#]

    [#|2013-08-27T17:11:57.972+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:\glassfish3\glassfish\domains\domain1\applications\admin-war recorded it as a pre-existing stale file|#]

    [#|2013-08-27T17:11:57.973+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:\glassfish3\glassfish\domains\domain1\applications\admin-war recorded it as a pre-existing stale file|#]

    [#|2013-08-27T17:11:57.974+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:\glassfish3\glassfish\domains\domain1\applications\admin-war recorded it as a pre-existing stale file|#]

    [#|2013-08-27T17:11:57.990+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:\glassfish3\glassfish\domains\domain1\applications\admin-war recorded it as a pre-existing stale file|#]

    [#|2013-08-27T17:11:57.991+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:\glassfish3\glassfish\domains\domain1\applications\admin-war recorded it as a pre-existing stale file|#]

    [#|2013-08-27T17:11:58.006+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:\glassfish3\glassfish\domains\domain1\applications\admin-war recorded it as a pre-existing stale file|#]

    [#|2013-08-27T17:11:58.008+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:\glassfish3\glassfish\domains\domain1\applications\admin-war recorded it as a pre-existing stale file|#]

    [#|2013-08-27T17:11:58.008+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:\glassfish3\glassfish\domains\domain1\applications\admin-war recorded it as a pre-existing stale file|#]

    [#|2013-08-27T17:11:58.024+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:\glassfish3\glassfish\domains\domain1\applications\admin-war recorded it as a pre-existing stale file|#]

    [#|2013-08-27T17:11:58.025+0200|WARNING|glassfish3.1.2|javax.enterprise.system.tools.deployment.com.sun.enterprise.deploy.shared|_ThreadID=29;_ThreadName=Thread-2;|DPL8031: Ignoring WEB-INF/ because the containing archive C:\glassfish3\glassfish\domains\domain1\applications\admin-war recorded it as a pre-existing stale file|#]

    [#|2013-08-27T17:11:58.026+0200|SEVERE|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=29;_ThreadName=Thread-2;|Module type not recognized for module C:\glassfish3\glassfish\domains\domain1\applications\admin-war|#]

    [#|2013-08-27T17:11:58.026+0200|SEVERE|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=29;_ThreadName=Thread-2;|There is no installed container capable of handling this application admin-war|#]

    [#|2013-08-27T17:11:58.087+0200|INFO|glassfish3.1.2|org.glassfish.admingui|_ThreadID=28;_ThreadName=Thread-2;|Exception Occurred :Error occurred during deployment: There is no installed container capable of handling this application admin-war. Please see server.log for more details.|#]

    最佳答案

    我对 OSGI 不太熟悉,但您需要在 AppModule 中使用 build* 方法来提供 DAO。在下面的示例中,我假设 OsgiBundle 是访问 OSGI 服务的一种方式,但我不知道实际的 OSGI 类是什么。

    例如:

    public class MyAppModule {
    public void contributeApplicationDefaults(MappedConfiguration<String, String> config) {
    config.add("osgi.path", "path/to/osgi.xml");
    }

    public OsgiBundle buildOsgiBundle(@Symbol("osgi.path") String osgiPath) {
    // lookup the OSGI bundle somehow
    }

    public MyDao buildMyDao(OsgiBundle osgiBundle) {
    return osgiBundle.getService(MyDao.class);
    }

    public SomeOtherDao buildSomeOtherDao(OsgiBundle osgiBundle) {
    return osgiBundle.getService(SomeOtherDao.class);
    }
    }

    如果您想要更深入的集成(即自动将所有 OSGI 服务发布为 Tapestry IOC 服务),请查看将所有 Spring bean 发布为 Tapestry IOC 服务的 TapestrySpringFilter。

    关于web-applications - 如何在 Tapestry 中使用 OSGi 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18399138/

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