I am getting Null Pointer Exception during server startup in the first line.
public class DefaultAreaPostalCodeService extends AbstractBusinessService implements AreaPostalCodeService {
private Map<String,List<PostalCodeData>> suburbMap;
@PostConstruct
@Transactional
public void initialize() {
List<AreaPostalCodeModel> postalCodes = areaPostalCodeDao.getAllAreaPostalCodes();
populateSuburbMap(postalCodes);
}
}
<bean id="areaPostalCodeService"
class="za.co.testro.core.address.impl.DefaultAreaPostalCodeService" parent="abstractBusinessService">
<property name="areaPostalCodeDao" ref="areaPostalCodeDao" />
</bean>
I simply want to populate the suburbMap at server startup so that I can use it later.
Error logs-
Error creating bean with name 'areaPostalCodeService': Invocation of init method failed; nested exception is java.lang.NullPointerException WARN [localhost-startStop-1] [CloseAwareApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'areaPostalCodeService': Invocation of init method failed; nested exception is java.lang.NullPointerException Pinging the JVM took 10 seconds to respond. ERROR [localhost-startStop-1] [HybrisContextFactory] Error initializing global application context! org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'areaPostalCodeService': Invocation of init method failed; nested exception is java.lang.NullPointerException at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136) ~[spring-beans-4.3.3.REL
EDIT 1:
I am still getting Null Pointer Exception after adding my code to afterProperties().
INFO [localhost-startStop-1] [ListMergeDirectiveBeanPostProcessor] Post Processing ListMergeDirective [promotionActionResultRaoExtractorListMergeDirective] on Bean [cartRAOProviderExtractors] WARN [localhost-startStop-1] [CloseAwareApplicationContext] Exception encoujava.lang.NullPointerException WARN [localhost-startStop-1] [CloseAwareApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'areaPostalCodeService' defined in class path resource [testcore-spring.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException ERROR [localhost-startStop-1] [HybrisContextFactory] Error initializing global application context! org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'areaPostalCodeService' defined in class path resource [testcore-spring.xml]: Invocation of init method failed; ne sted exception is java.lang.NullPointerException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]ntered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'areaPostalCodeService' defined in class path resource [testcore-spring.xml]: Invocation of init method failed; nested exception is
EDIT 2:
Still getting Null Pointer Exception after calling the bean with application context.
Registry.getApplicationContext().getBean("areaPostalCodeDao", AreaPostalCodeDao.class).getAllAreaPostalCodes()
Error logs-
INFO [localhost-startStop-1] [ListMergeDirectiveBeanPostProcessor] Post Processing ListMergeDirective [promotionActionResultRaoExtractorListMergeDirective] on Bean [cartRAOProviderExtractors] WARN [localhost-startStop-1] [CloseAwareApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'areaPostalCodeService' defined in class path resource [testcore-spring.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException WARN [localhost-startStop-1] [CloseAwareApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'areaPostalCodeService' defined in class path resource [testcore-spring.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException ERROR [localhost-startStop-1] [HybrisContextFactory] Error initializing global application context! org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'areaPostalCodeService' defined in class path resource [testcore-spring.xml]: Invocation of init method failed; ne sted exception is java.lang.NullPointerException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
Caused by: org.springframework.beans.FatalBeanException: Context hybris Global Context Factory couldn't be created correctly due to, Error creating bean with name 'areaPostalCodeService' defined in class path resource [testcore-spring.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException at de.hybris.platform.core.HybrisContextFactory.build(HybrisContextFactory.java:314)
BeanCreationException
, postDefaultAreaPostalCodeService
code – gvmani@Transactional
annotation. If it works, change your class to a child class ofInitializingBean
and use@AfterPropertiesSet
annotation instead of@PostConstruct
as setters injections aren't called in post-construct yet. – Edward Aung