Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring应用程序-向侦听器i发送上下文初始化事件时发生异常_Java_Spring_Jvm - Fatal编程技术网

Java Spring应用程序-向侦听器i发送上下文初始化事件时发生异常

Java Spring应用程序-向侦听器i发送上下文初始化事件时发生异常,java,spring,jvm,Java,Spring,Jvm,我有一个JavaSpring应用程序,它使用Spring3.0.7和以下SpringJAR 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-expre

我有一个JavaSpring应用程序,它使用Spring3.0.7和以下SpringJAR

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

此应用程序在许多虚拟机中运行良好。但是在一个VM中,它在服务器启动时抛出以下异常

Exception sending context initialized event to listener instance of
    class org.springframework.web.context.ContextLoaderListener
任何指点都很感激

整个异常堆栈跟踪:

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();
        }
    }

查看异常的最后一部分:

Error creating bean with name 'testCache': 
    Invocation of init method failed; nested exception is
    com.google.common.util.concurrent.UncheckedExecutionException:
    java.lang.NullPointerException
您的
testCache
bean的init方法看起来如何-这就是错误所在(NullPointerException)


干杯,

发布整个例外。不要将你的整个帖子格式化为代码。谢谢Boris的回复。更新了整个例外情况。在某些情况下,您的
CacheLoader
会为
本地化返回
null
。番石榴缓存不能有
null
键。顺便问一句,为什么在地球上你有一个8小时的到期,然后一个单独的线程刷新元素每5分钟??这一切似乎都很狡猾。5分钟后就到期了,你是说每5分钟到期一次就够了吗?不需要刷新吗?cache=CacheBuilder.newBuilder();添加了init方法。我看不出init有什么问题是的,你是正确的init方法就是问题所在。我正在使用谷歌缓存。这造成了问题。谢谢你找出了真正的问题。仍然在寻找谷歌缓存造成问题的原因……非常感谢@Anders R.Bystrup!我的问题解决了。如果您看到在我的init方法中,缓存上没有空检查。在添加空检查之后,它开始完美地工作。再次感谢!我没有足够的声誉来接受你的回答。你救了我一天。很好,你找到了根本原因。快乐编码@用户1457957您不需要任何声誉就可以。你需要声誉来提高投票率。如果这个答案解决了你的问题,请接受。