gpt4 book ai didi

java - Jira插件开发如何获取RapidViewServiceImpl实例

转载 作者:行者123 更新时间:2023-12-01 17:56:28 25 4
gpt4 key购买 nike

我正在使用 Java 开发 Jira 报告插件,我需要获取 RapidViewServiceImpl 类的实例。如果我使用构造函数,我会得到 nullPtrException 并且我认为还有另一种方法来获取此实例。例如,我对 SprintManagerSprintManagerImpl 遇到了完全相同的问题,我得到的实例如下:

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”的包。这是错误的一部分,我无法发布整个错误,因为太长了:

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$000(ConfigureReport.java:53) [?:?]
at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport$ObjectConfigurationField.getValues(ConfigureReport.java:440) [?:?]
... 387 more

有人可以帮我解决这个问题吗?

最佳答案

我通过使用类 ProjectRapidViewServiceImpl 解决了这个问题,并使用名为“projectRapidViewServiceImpl”的包获取了该类的实例

private com.atlassian.greenhopper.service.rapid.ProjectRapidViewService getRapidViewManager() throws InvalidSyntaxException {    
ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
if (appCtx != null) {
return (ProjectRapidViewServiceImpl) appCtx.getBean("projectRapidViewServiceImpl");
}
return null;
}

这个类有一个名为 findRapidViewsByProject(com.atlassian.jira.user.ApplicationUser user, com.atlassian.jira.project.Project project) 的函数,它返回与项目。

关于java - Jira插件开发如何获取RapidViewServiceImpl实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60707988/

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