Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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 springbean字段(显式实例化)有时被分配为null_Java_Spring_Nullpointerexception_Javabeans_Explicit Instantiation - Fatal编程技术网

Java springbean字段(显式实例化)有时被分配为null

Java springbean字段(显式实例化)有时被分配为null,java,spring,nullpointerexception,javabeans,explicit-instantiation,Java,Spring,Nullpointerexception,Javabeans,Explicit Instantiation,有一天,我们遇到了一个事件,应用程序因为NPE而开始崩溃。我找到了它坠毁的地方,但我不能确定它为什么会发生 粗略地说,让我们假设我有一个类a,它同时出现一个Springbean。这个类有一个显式实例化的字段属性(是的,我知道它听起来是什么样子)和一个使用这个字段的方法propertyUser: class A { private ObjectClass property = new ObjectClass(); public void propertyUser() { p

有一天,我们遇到了一个事件,应用程序因为NPE而开始崩溃。我找到了它坠毁的地方,但我不能确定它为什么会发生

粗略地说,让我们假设我有一个类a,它同时出现一个Springbean。这个类有一个显式实例化的字段属性(是的,我知道它听起来是什么样子)和一个使用这个字段的方法propertyUser

class A {
   private ObjectClass property = new ObjectClass();
   public void propertyUser() {
      property.action();
   }   
   ....
   getter\setter for property
}
经过一段时间的正常工作后,属性字段变为空,这导致了propertyUser方法的NPE。 我更改了这个遗留代码,现在这个属性也通过spring容器分配,但是我需要确定这是出现此错误的原因


因此,如果有人能给我一个提示,我将非常高兴。

检查相应setter的所有用法。也许你有
a.setproperty(reference)
的某个地方引用为空?重复检查-否,setter不在任何地方使用。反射?是否有一些序列化过程?它存储在服务器端会话中?不,列表中没有任何内容发生。这个bean(我指的是类A)就像在一个mvc控制器中注入的bean一样使用。它不存储任何东西,也不存储在任何地方。并且该属性只能通过该bean访问(有几个方法被委派)。Getter甚至没有在任何地方使用。您确定检查的代码版本与当时部署的完全相同吗?