Null-Pointer-Exception when using TaskListener with Spring Boot Starter

Hey,

I am currently trying to migrate a classic WAR Deployment to a standalone server with spring-boot-starter.

Unfortunately I cant get the TaskListener to initiate correctly. The application always throws the following exception:

15:29:11.938 [main] ERROR o.s.boot.SpringApplication - Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'notifyCandidatesListener' defined in class path resource [de/ecclesia/bpmn/eflowserver/geschaeftsprozesse/delegates/DelegateConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.ecclesia.bpmn.eflowserver.geschaeftsprozesse.delegates.CandidatesListener]: Factory method 'notifyCandidatesListener' threw exception; nested exception is java.lang.NullPointerException at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) at de.ecclesia.bpmn.eflowserver.EflowServerApplication.main(EflowServerApplication.java:15) Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.ecclesia.bpmn.eflowserver.geschaeftsprozesse.delegates.CandidatesListener]: Factory method 'notifyCandidatesListener' threw exception; nested exception is java.lang.NullPointerException at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ... 19 common frames omitted Caused by: java.lang.NullPointerException: null at de.ecclesia.bpmn.eflowserver.geschaeftsprozesse.delegates.CandidatesListener.<init>(CandidatesListener.java:32) at de.ecclesia.bpmn.eflowserver.geschaeftsprozesse.delegates.DelegateConfiguration.notifyCandidatesListener(DelegateConfiguration.java:11) at de.ecclesia.bpmn.eflowserver.geschaeftsprozesse.delegates.DelegateConfiguration$$EnhancerBySpringCGLIB$$e9659d88.CGLIB$notifyCandidatesListener$0(<generated>) at de.ecclesia.bpmn.eflowserver.geschaeftsprozesse.delegates.DelegateConfiguration$$EnhancerBySpringCGLIB$$e9659d88$$FastClassBySpringCGLIB$$5a9fcf5d.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) at de.ecclesia.bpmn.eflowserver.geschaeftsprozesse.delegates.DelegateConfiguration$$EnhancerBySpringCGLIB$$e9659d88.notifyCandidatesListener(<generated>) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ... 20 common frames omitted

I started with the TaskListener beeing annotated as @Named(ÔÇťnotifyCandidatesListenerÔÇŁ), later on I tried @Service, @Component.

Somewhere on this forum I read that I would need a configurationclass to initialize the TaskListener:
@Configuration
public class DelegateConfiguration {

@Bean
CandidatesListener notifyCandidatesListener() {
    return new CandidatesListener();
}

}

This wont change anything. This is my Listener:
public class CandidatesListener implements TaskListener {

private final Logger LOGGER = Logger.getLogger(MailTask.class.getName());

private MailService mailservice = new MailService();
private IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService();

private Expression absender;
private Expression nachricht;

protected EntityManager entityManager;

@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
    this.entityManager = entityManager;
}

@Override
public void notify(DelegateTask delegateTask) {
    DelegateExecution execution = delegateTask.getExecution();
.... code
}

}

Hi @Pommes9485,

I think the problem is that the bean could not be created successfully, maybe because of the persistence context itÔÇÖs referencing.

Have you tried to access the notify method directly in a test without the process engine?

Viele Gr├╝├če aus der Elisabethstr. in die Klingenbergstra├če :slight_smile:

Ingo

1 Like

Hey @Ingo_Richtsmeier,

that was exactly the issue. After I rewrote those context statements to retrieve the services via injection, everything worked perfectly. When I was reading the exception message, I somehow completely forgot to check the line 32 in my CandidateListener class :sweat_smile:

Now everything seems to be working fine, unfortunately I am not able to find that much documentation for the spring boot starter.

Viele Gr├╝├če zur├╝ck! Was f├╝r ein Zufall.