팩토리 클래스의 생성자에서 내 팩토리 클래스에 대한 일부 구성으로로드 할 개인 정적 속성 개체를 설정했습니다. 내가 클래스를 초기화 할 때개인 정적 속성 변수로 인해 널 포인터 예외가 발생합니다.
public class BussinessServiceFactory {
private static final BussinessServiceFactory factory = new BussinessServiceFactory();
public static BussinessServiceFactory createBussinessServiceFactory(){
return factory;
}
private BussinessServiceFactory(){
InputStream in = BussinessServiceFactory.class.getClassLoader().getResourceAsStream("factory/bussinessservice.properties");
try {
bsConfig.load(in);
} catch (IOException exception) {
// TODO Auto-generated catch block
throw new RuntimeException(exception);
}
}
private static Properties bsConfig = new Properties();
public <T> T createBussinessService(Class<T> clazz){
try {
String clazzName = clazz.getSimpleName();
String name = bsConfig.getProperty(clazzName);
return (T) Class.forName(name).newInstance();
} catch (InstantiationException | IllegalAccessException
| ClassNotFoundException exception) {
throw new RuntimeException(exception);
}
}
}
그러나, 그것은 NullPointerException
가 발생합니다.
java.lang.NullPointerException
at factory.BussinessServiceFactory.<init>(BussinessServiceFactory.java:15)
at factory.BussinessServiceFactory.<clinit>(BussinessServiceFactory.java:8)
... 24 more
그런 다음 속성 개체를 비 정적 개체로 변경하면 문제가 해결됩니다. 그러나 나는 왜 이런 일이 일어나고 어떻게 이런 식으로 해결 될 수 있는지에 대한 이유에 대해 혼란 스럽습니다.
글쎄, 문제는 * testFindOrder *에 문제가 있으며 * testPageQuery *를 표시하고 있다고합니다. 우리가 어떻게 당신을 도울까요? – CKing