首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >汇合插件组件的bean作用域是什么?如何控制它?

汇合插件组件的bean作用域是什么?如何控制它?
EN

Stack Overflow用户
提问于 2015-08-23 14:27:12
回答 1查看 257关注 0票数 1

我开发了一个汇合插件使用亚特兰西安sdk。在使用plugins-version 2时,根据also的文档,对于每一个bean都是实例化的,如果bean是公共的,那么它也被公开为OSGI服务(我可以在Felix控制台上看到)。(见亚特兰西安多古.)

到目前为止,我在我的汇合插件中有三个共通插件,其中一个是公开的,另一个是“私有”(public="false")。我的主bean (名为“工件-存储”)是公共的-我在一些宏类中使用并通过构造函数注入它。在atlassian-plugin.xml中,我声明了如下组件:

代码语言:javascript
运行
复制
<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>

亚特兰西安·多库说:“每种使用都创建实例(原型-范围).”我对此表示怀疑。在调试宏时,我总是看到同一个实例“工件-存储”,这就是为什么我认为范围不是“原型”的原因。这对我来说很好,我想要范围“单例”,但我不确定它是否真的是。

为了进一步控制bean,亚特兰西安建议在META/ spring /中声明bean,因此我创建了spring "definition“artifact-info-plugin/src/main/resources/META-INF/spring/artifact-info-plugin.xml;我在那里添加了一个bean:

代码语言:javascript
运行
复制
<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中,我将组件定义更改为:

代码语言:javascript
运行
复制
<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)也不再可用。

总结以下问题:

  • 汇合插件<component/>的bean作用域是什么?
  • 对于公共组件bean和“私有”组件bean,作用域是否相同?
  • 如何确保有一个单例作用域bean?
  • 真的可以在META-INF/spring/beans.xml中声明组件bean吗?如果是,怎么做?你能举个简短的例子吗?

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

代码语言:javascript
运行
复制
<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文件、plugin和beans作为注释。

EN

回答 1

Stack Overflow用户

发布于 2015-08-24 08:23:03

汇合插件的bean范围是什么?

是单身

对于公共组件bean和“私有”组件bean,作用域是否相同?

如何确保有一个单例作用域bean?

如果在亚特兰-plugin.xml中定义,它们已经是单例了。

真的有可能在META/spring/beans.xml中声明组件bean吗?如果是,怎么做?你能举个简短的例子吗?

我从未尝试过定义beans.xml。我只有spring注释配置:添加了src/main/resources/META/spring/Spring.xml,内容如下:

代码语言:javascript
运行
复制
<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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32167708

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档