user1457957
user1457957

Reputation: 305

Java Spring application - Exception sending context initialized event to listener i

I have java spring application which uses spring 3.0.7 with the following spring jars

spring-aop-3.0.7.RELEASE.jar

spring-asm-3.0.7.RELEASE.jar

spring-beans-3.0.7.RELEASE.jar

spring-context-3.0.7.RELEASE.jar

spring-core-3.0.7.RELEASE.jar

spring-data-jdbc-core-1.0.0.RELEASE.jar

spring-expression-3.0.7.RELEASE.jar

spring-jdbc-3.0.7.RELEASE.jar

spring-tx-3.0.7.RELEASE.jar

spring-web-3.0.7.RELEASE.jar

This application is working fine in many of the VMs. But in one VM it throws the following exception while the server starts up.

Exception sending context initialized event to listener instance of
    class org.springframework.web.context.ContextLoaderListener

Any pointers is appreciated.

Entire exception stacktrace:

INFO: Initializing Spring root WebApplicationContext
May 13, 2015 3:28:01 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testCacheLoader': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.util.localization.LoadLocaleMessage com.caching.testCacheLoader.llm; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadLocaleMessage': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.common.dao.CommonDAO com.util.localization.LoadLocaleMessage.commonDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.caching.testCache com.common.dao.CommonDAOImpl.testCache; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testCache': Invocation of init method failed; nested exception is com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)

@PostConstruct
public void init() { 
    cache = CacheBuilder.newBuilder().maximumSize(100)
                .refreshAfterWrite(8, TimeUnit.HOURS).removalListener(listener)
                .build(loader);

        ScheduledExecutorService ses = Executors
                .newSingleThreadScheduledExecutor();

        ses.scheduleWithFixedDelay(new Runnable() {
            public void run() {
                for (String key : cache.asMap().keySet()) {
                    cache.refresh(key);
                    logger.info("Refreshing cache . . . . ");
                }
            }
        }, 0, 5, TimeUnit.MINUTES);

        try {
            cache.get("LOCALIZATION");
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

Upvotes: 1

Views: 1383

Answers (1)

Anders R. Bystrup
Anders R. Bystrup

Reputation: 16080

Look at the last part of the exception:

Error creating bean with name 'testCache': 
    Invocation of init method failed; nested exception is
    com.google.common.util.concurrent.UncheckedExecutionException:
    java.lang.NullPointerException

How does the init-method of your testCache bean look - that's where the fault is (a NullPointerException).

Cheers,

Upvotes: 3

Related Questions