Jira插件开发如何获取RapidViewServiceImpl实例
Jira plugin development how to get RapidViewServiceImpl instance
我正在使用 Java 开发 Jira 报告插件,我需要获取 RapidViewServiceImpl
class 的实例。
如果我使用构造函数,我会得到一个 nullPtrException 并且我认为还有另一种方法来获取这个实例。
例如,我对 SprintManager
和 SprintManagerImpl
有完全相同的问题,我得到的实例如下:
private com.atlassian.greenhopper.service.sprint.SprintManager getSprintManager() throws InvalidSyntaxException {
ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
if (appCtx != null) {
return (com.atlassian.greenhopper.service.sprint.SprintManager) appCtx.getBean("sprintManagerImpl");
}
return null;
}
private Object getGreenHopperAppCtx() throws InvalidSyntaxException {
OsgiContainerManager osgi = ComponentAccessor.getComponentOfType(OsgiContainerManager.class);
if (osgi == null) {
java.lang.System.out.println("OSGI Not Found");
return null;
}
Bundle[] bundles = osgi.getBundles();
for (int i = 0; i < bundles.length; i++) {
Bundle bundle = bundles[i];
if ("com.pyxis.greenhopper.jira".equals(bundle.getSymbolicName())) {
BundleContext bctx = bundle.getBundleContext();
ServiceReference[] refs = bctx.getAllServiceReferences(null, null);
if (refs != null) {
for (int j = 0; j < refs.length; j++) {
Object prop = refs[j].getProperty("org.springframework.context.service.name");
if ("com.pyxis.greenhopper.jira".equals(prop)) {
return bctx.getService(refs[j]);
}
}
}
}
}
return null;
}
在主函数中我调用了SprintManager spManager = getSprintManager()
。
我用 RapidViewServiceImpl
:
尝试了同样的事情
private Object getGreenHopperAppCtx() throws InvalidSyntaxException {
OsgiContainerManager osgi = ComponentAccessor.getComponentOfType(OsgiContainerManager.class);
if (osgi == null) {
java.lang.System.out.println("OSGI Not Found");
return null;
}
Bundle[] bundles = osgi.getBundles();
for (int i = 0; i < bundles.length; i++) {
Bundle bundle = bundles[i];
if ("com.pyxis.greenhopper.jira".equals(bundle.getSymbolicName())) {
BundleContext bctx = bundle.getBundleContext();
ServiceReference[] refs = bctx.getAllServiceReferences(null, null);
if (refs != null) {
for (int j = 0; j < refs.length; j++) {
Object prop = refs[j].getProperty("org.springframework.context.service.name");
if ("com.pyxis.greenhopper.jira".equals(prop)) {
return bctx.getService(refs[j]);
}
}
}
}
}
return null;
}
//------------------------------------------------------------------------------------------------------------------
private com.atlassian.greenhopper.service.rapid.view.RapidViewService getRapidViewManager() throws InvalidSyntaxException {
ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
if (appCtx != null) {
return (RapidViewService) appCtx.getBean("rapidViewService");
}
return null;
}
但是我收到一条错误消息,提示没有名为“rapidViewService
”的包。
这是错误的一部分,我无法 post 整个错误,因为它太长了:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'rapidViewService' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054) [spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at com.jiraPlugin.utility.SprintManager.getRapidViewManager(SprintManager.java:72) [?:?]
at com.jiraPlugin.utility.SprintManager.getListOfSprints(SprintManager.java:95) [?:?]
at com.jiraPlugin.utility.GetSprintsForUI.getValues(GetSprintsForUI.java:35) [?:?]
at com.atlassian.configurable.ValuesGeneratorObjectConfigurationProperty.getInternalValues(ValuesGeneratorObjectConfigurationProperty.java:75) [classes/:?]
at com.atlassian.configurable.ObjectConfigurationPropertyImpl.entrySet(ObjectConfigurationPropertyImpl.java:266) [classes/:?]
at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport.mapAndConvertToList(ConfigureReport.java:383) [?:?]
at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport.access[=12=]0(ConfigureReport.java:53) [?:?]
at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport$ObjectConfigurationField.getValues(ConfigureReport.java:440) [?:?]
... 387 more
有人可以帮我解决这个问题吗?
我使用 class ProjectRapidViewServiceImpl 解决了这个问题,并且我使用名为 "projectRapidViewServiceImpl"
的包获得了这个 class 的实例
private com.atlassian.greenhopper.service.rapid.ProjectRapidViewService getRapidViewManager() throws InvalidSyntaxException {
ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
if (appCtx != null) {
return (ProjectRapidViewServiceImpl) appCtx.getBean("projectRapidViewServiceImpl");
}
return null;
}
并且这个 class 有一个名为 findRapidViewsByProject(com.atlassian.jira.user.ApplicationUser user, com.atlassian.jira.project.Project project)
的函数,其中 returns 一个与项目相关的 RapidViews 列表。
我正在使用 Java 开发 Jira 报告插件,我需要获取 RapidViewServiceImpl
class 的实例。
如果我使用构造函数,我会得到一个 nullPtrException 并且我认为还有另一种方法来获取这个实例。
例如,我对 SprintManager
和 SprintManagerImpl
有完全相同的问题,我得到的实例如下:
private com.atlassian.greenhopper.service.sprint.SprintManager getSprintManager() throws InvalidSyntaxException {
ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
if (appCtx != null) {
return (com.atlassian.greenhopper.service.sprint.SprintManager) appCtx.getBean("sprintManagerImpl");
}
return null;
}
private Object getGreenHopperAppCtx() throws InvalidSyntaxException {
OsgiContainerManager osgi = ComponentAccessor.getComponentOfType(OsgiContainerManager.class);
if (osgi == null) {
java.lang.System.out.println("OSGI Not Found");
return null;
}
Bundle[] bundles = osgi.getBundles();
for (int i = 0; i < bundles.length; i++) {
Bundle bundle = bundles[i];
if ("com.pyxis.greenhopper.jira".equals(bundle.getSymbolicName())) {
BundleContext bctx = bundle.getBundleContext();
ServiceReference[] refs = bctx.getAllServiceReferences(null, null);
if (refs != null) {
for (int j = 0; j < refs.length; j++) {
Object prop = refs[j].getProperty("org.springframework.context.service.name");
if ("com.pyxis.greenhopper.jira".equals(prop)) {
return bctx.getService(refs[j]);
}
}
}
}
}
return null;
}
在主函数中我调用了SprintManager spManager = getSprintManager()
。
我用 RapidViewServiceImpl
:
private Object getGreenHopperAppCtx() throws InvalidSyntaxException {
OsgiContainerManager osgi = ComponentAccessor.getComponentOfType(OsgiContainerManager.class);
if (osgi == null) {
java.lang.System.out.println("OSGI Not Found");
return null;
}
Bundle[] bundles = osgi.getBundles();
for (int i = 0; i < bundles.length; i++) {
Bundle bundle = bundles[i];
if ("com.pyxis.greenhopper.jira".equals(bundle.getSymbolicName())) {
BundleContext bctx = bundle.getBundleContext();
ServiceReference[] refs = bctx.getAllServiceReferences(null, null);
if (refs != null) {
for (int j = 0; j < refs.length; j++) {
Object prop = refs[j].getProperty("org.springframework.context.service.name");
if ("com.pyxis.greenhopper.jira".equals(prop)) {
return bctx.getService(refs[j]);
}
}
}
}
}
return null;
}
//------------------------------------------------------------------------------------------------------------------
private com.atlassian.greenhopper.service.rapid.view.RapidViewService getRapidViewManager() throws InvalidSyntaxException {
ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
if (appCtx != null) {
return (RapidViewService) appCtx.getBean("rapidViewService");
}
return null;
}
但是我收到一条错误消息,提示没有名为“rapidViewService
”的包。
这是错误的一部分,我无法 post 整个错误,因为它太长了:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'rapidViewService' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054) [spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at com.jiraPlugin.utility.SprintManager.getRapidViewManager(SprintManager.java:72) [?:?]
at com.jiraPlugin.utility.SprintManager.getListOfSprints(SprintManager.java:95) [?:?]
at com.jiraPlugin.utility.GetSprintsForUI.getValues(GetSprintsForUI.java:35) [?:?]
at com.atlassian.configurable.ValuesGeneratorObjectConfigurationProperty.getInternalValues(ValuesGeneratorObjectConfigurationProperty.java:75) [classes/:?]
at com.atlassian.configurable.ObjectConfigurationPropertyImpl.entrySet(ObjectConfigurationPropertyImpl.java:266) [classes/:?]
at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport.mapAndConvertToList(ConfigureReport.java:383) [?:?]
at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport.access[=12=]0(ConfigureReport.java:53) [?:?]
at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport$ObjectConfigurationField.getValues(ConfigureReport.java:440) [?:?]
... 387 more
有人可以帮我解决这个问题吗?
我使用 class ProjectRapidViewServiceImpl 解决了这个问题,并且我使用名为 "projectRapidViewServiceImpl"
的包获得了这个 class 的实例private com.atlassian.greenhopper.service.rapid.ProjectRapidViewService getRapidViewManager() throws InvalidSyntaxException {
ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
if (appCtx != null) {
return (ProjectRapidViewServiceImpl) appCtx.getBean("projectRapidViewServiceImpl");
}
return null;
}
并且这个 class 有一个名为 findRapidViewsByProject(com.atlassian.jira.user.ApplicationUser user, com.atlassian.jira.project.Project project)
的函数,其中 returns 一个与项目相关的 RapidViews 列表。