Spring init-method="init"加载方法的例子

最好连接数据库的init()

第1个回答  2013-02-21
<beans>
<bean id="test" class="test.Test" init-method="init">
<property name="name">
<value>chenhaibin</value>
</property>
</bean>
</beans>

在Test实例化对象的时候,执行init这个方法。追问

我现在想知道init()方法是咋从数据库里读取数据的,我现在就是init()打印控制台是没有任何问题,只是一从数据库里提取数据就报错,org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'test' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException

追答

不是写了BeanCreationException错误嘛 , 是不是你引用的时候写错了

追问

我不是说了吗,init()打印控制台是没有任何问题,只是一从数据库里提取数据就报错