Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Lifecycle aware component not instantiated in JIRA 7 with spring scanner

Sebastien Delcoigne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 3, 2016

I have already used the PluginScheduler in previous plugins with older JIRAs before and I wanted to adapt some code to JIRA 7 and the SchedulerService. In order to schedule my job, I thought I'd use a LifeCycleAware component that would register the JobRunner and schedule a job with it, similar as what Chris Fuller's example does, but I haven't been able to have the component instantiated so far.

UPM installs the plugin without a fuss and I do not see any error in the spring debug logs.

Is it a lack of explicit dependency import in the maven JIRA plugin ? A wrong scope for some dependencies ? Missing annotations ? Any hints would be greatly appreciated.

 

Regards,

 

Sebastien Delcoigne

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
crf
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 3, 2016

Is the component you need marked with @ComponentImport or @Inject?  Is the class marked with @Scanned?  I understand that @Scanned will go away at some point, but maybe that hasn't happened yet.  I haven't used the scanner much myself as yet.

0 votes
Deniz Oğuz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2017

I have finally solved this. You need to add @ExportAsService annotation in addition to @Component annotation

@Component
@ExportAsService(LifecycleAware.class)
vvasic75 April 19, 2017

Hello Deniz,

sorry but can you please explain a little how you solved this problem using LifecycleAware with Atlassian Spring Scanner?

Can you please share your class which is implementing LifecycleAware?

I have a same problem and here is my class:

@Named("myClassLauncher")
@ExportAsService(LifecycleAware.class)
public class MyClassLauncher implements LifecycleAware, InitializingBean, DisposableBean {

    private static final Logger LOGGER = LoggerFactory.getLogger(MyClassLauncher.class);

    private final MyClassScheduleManager myClassScheduleManager;

    @Inject
    public MyClassLauncher(MyClassScheduleManager myClassScheduleManager) {
        this.myClassScheduleManager = myClassScheduleManager;
    }

    @Override
    public void onStart() {
        LOGGER.info("LifecycleAware - onStart");
    }

    @Override
    public void onStop() {
        LOGGER.info("LifecycleAware - onStop");
    }

    @Override
    public void destroy() throws Exception {
        LOGGER.info("unregisterListeners");
        LOGGER.info("unregisterJobRunner");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        LOGGER.info("AFTER_PROPERTIES_SET");
    }


    /**
     * This is received from the plugin system after the plugin is fully initialized.
     */
    @EventListener
    public void onPluginEnabled(PluginEnabledEvent event) {
        LOGGER.info("PLUGIN_ENABLED");
    }

 Now, I get "AFTER_PROPERTIES_SET" and "PLUGIN_ENABLED", but I can not get "LifecycleAware - onStart" in log, meaning that I failed initializing this properly.

Is this:

@Component
@ExportAsService(LifecycleAware.class)

instead of:

@Named("myClassLauncher")
@ExportAsService(LifecycleAware.class)

enough?

Do I need some other related changes in atlassian-plugin.xml or pom.xml?

Thanks.

Diego Ferreira
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 19, 2017

Hey @vvasic75

I know it's been a while since you've asked, but just to let this be registered here...

you can use something like 

public void afterPropertiesSet() throws Exception {
registerListener();
onLifecycleEvent(LifecycleEvent.AFTER_PROPERTIES_SET);

if (lifecycleManager.isApplicationSetUp())
onLifecycleEvent(LifecycleEvent.LIFECYCLE_AWARE_ON_START);
}

 ... so you trigger the AWARE_ON_START event even on simple deploy - if LifecycleManager informs you that the ApplicationsSetUp().

 

Hope this helps someone ;)

0 votes
Deniz Oğuz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2017

Hi,

I have the same problem. I'm using spring scanner 1.2.13. Everything was fine until I need to use PluginScheduler. My component is annotated with @Component and implements LifecycleAware. onStart method is never triggered although component is instantiated.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events