我正在尝试在单例类中注入一个原型对象..
public class Triangle implements ApplicationContextAware{
private Point pointA;
private ApplicationContext context=null;
Point point=(Point)context.getBean("pointA",Point.class);
public void draw(){
System.out.println("The prototype point A is ("+point.getX()+","+point.getY()+")");
}
@Override
public void setApplicationContext(ApplicationContext context)
throws BeansException {
this.context=context;
}
}
我用坐标 x 和 y 创建了一个 Point java 文件。
当我尝试编译上述代码时,出现以下错误
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'triangle' defined in class path resource [Spring.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.david.shape.Triangle]: Constructor threw exception; nested exception is java.lang.NullPointerException