【发布时间】:2013-03-26 01:29:52
【问题描述】:
我有一个这样的豆子:
@Component
@DependsOn("SomeType")
Class A{
@Autowired
SomeType one;
String two = one.someMethod();
int three;
}
In my application context xml, I have:
<bean id="two" class="a.b.c.SomeType"></bean>
<context:component-scan base-package="a.b.c"/>
<context:annotation-config/>
但是当 Spring 实例化 bean 时,它会抛出一个 NullPointerException。所以我想知道字段two 是否在字段one 之前初始化,导致NPE。谁能告诉我在 bean 中初始化字段的顺序是什么?
【问题讨论】:
标签: java spring nullpointerexception in-class-initialization