1

我使用 atlassian sdk 开发了一个 confluence 插件。根据 Atlassian 文档,使用插件版本 2 时,对于每个实例化的 bean,如果 bean 是公共的,它也会作为 OSGI 服务公开(我可以在 Felix 控制台上看到)。(参见地图集文档。)

到目前为止,我的 confluence 插件中有 3 个组件,其中一个是公共的,其他的是“私有的”(public =“false”)。我的主 bean(名为“artifact-store”) - 是公共的 - 我在一些宏类中使用并通过构造函数注入它。在atlassian-plugin.xml我已经声明了这样的组件:

<component key="artifact-store" class="info.magnolia.sys.confluence.plugin.artifactinfo.artifactstore.ArtifactCache" name="Artifact store to cache artifacts" public="true">
 <interface>info.magnolia.sys.confluence.plugin.artifactinfo.ArtifactSearch</interface>
  <description key="artifact-store.decription">Artifact store to cache artifacts based on Atlassian cache api.</description>
</component>

Atlassian 文档说:“实例是根据使用情况创建的(原型范围)......”我对此表示怀疑。在调试我的宏时,我总是看到相同的“artifact-store”实例,这就是为什么我认为范围不是“原型”。这对我来说很好,我想要范围“单例”,但我不确定它是否真的是。
为了进一步控制 bean,Atlassian 建议在 META-INF/spring/ 中声明 bean,因此我创建了 spring beans“定义” artifact-info-plugin/src/main/resources/META-INF/spring/artifact-info-plugin.xml;我在那里添加了一个bean:

<bean id="artifactSearchBean" class="info.magnolia.sys.confluence.plugin.artifactinfo.artifactstore.ArtifactCache" scope="singleton">
  <description>A bean chaching artifact data</description>
</bean>

在中,atlassian-plugin.xml我将组件定义更改为:

<component key="artifact-store" class="bean:artifactSearchBean" name="Artifact store to cache artifacts" public="true">
  <interface>info.magnolia.sys.confluence.plugin.artifactinfo.ArtifactSearch</interface>
  <description key="artifact-store.decription">Artifact store to cache artifacts based on Atlassian cache api.</description>
</component>

我已经尝试过了,但对我不起作用,没有更多的 bean 可用;没有创建任何组件;因此,宏(使用组件 bean)也不再可用。

总结一下问题:

  • confluence 插件的 bean 范围是<component/>什么?
  • 公共和“私有”组件 bean 的范围是否相同?
  • 我怎样才能确保有一个单例范围的 bean?
  • 真的可以在中声明组件beanMETA-INF/spring/beans.xml吗?如果是,如何?你能提供一个简短的例子吗?

关于我的环境的一些可能更有趣的信息:在 pom 中:

<confluence.version>5.8.9</confluence.version>
<confluence.data.version>5.8.9</confluence.data.version>
<amps.version>5.1.11</amps.version>

在 atlassian-plugin.xml 中:<atlassian-plugin plugins-version="2"/>

因为我不允许添加超过 2 个链接,所以我将添加到 pom 文件、插件 xml 和 beans xml 的完整链接作为注释。

4

1 回答 1

1

confluence 插件的 bean 范围是什么?

是单例

公共和“私有”组件 bean 的范围是否相同?

是的

我怎样才能确保有一个单例范围的 bean?

如果在 atlassian-plugin.xml 中定义,它们已经是单例的。

真的可以在 META-INF/spring/beans.xml 中声明组件 bean 吗?如果是,如何?你能提供一个简短的例子吗?

我从未尝试定义 beans.xml。我只有 spring 注释配置:添加了 src/main/resources/META-INF/spring/spring.xml 具有以下内容:

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
  <context:annotation-config />
  <context:component-scan base-package="com.jiraworkcalendar" />
</beans
于 2015-08-24T08:23:03.437 回答