我正在练习Spring,当我尝试实例化上下文时,我得到了一个java.lang.ExceptionInInitializerError异常.下面显示了Exception,我的代码跟随它.我从以前简化了我的实验.
例外
Oct 17,2012 5:54:22 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@570c16b7: startup date [Wed Oct 17 17:54:22 CDT 2012]; root of context hierarchy
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.springframework.context.support.AbstractRefreshableApplicationContext.createbeanfactory(AbstractRefreshableApplicationContext.java:195)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshbeanfactory(AbstractRefreshableApplicationContext.java:128)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshbeanfactory(AbstractApplicationContext.java:535)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:449)
at org.springframework.context.support.ClassPathXmlApplicationContext.beanfactory.beanfactory.java:105)
... 7 more
我的配置XML
我的考试班.
package helloworld;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class HelloWorldTest {
/**
* @param args
*/
public static void main(String[] args)
{
ApplicationContext context = new ClassPathXmlApplicationContext("HelloWorldTest-context.xml");
MessageContainer message = context.getBean(MessageContainer.class);
MessageOutputService service = context.getBean(MessageOutputService.class);
service.outputMessageToConsole(message);
}
}
最佳答案
第17行与context.getBean(“userRepository”行)不对应,它对应于初始化Spring上下文之前的行.实际上你也可以通过stacktrace看到它在ClassPathXmlApplicationContext的第83行上失败了存在该类的构造函数.
原文链接:https://www.f2er.com/spring/431472.html无论如何,当Spring无法出于任何原因创建任何bean时,通常会抛出此异常(构造函数中的异常,resource loading issues,class loading issues等).我建议降低spring类和你自己的库的日志级别,看看下面发生了什么.
org.springframework=TRACE
com.gamemanagertest=TRACE
com.gamemanagertest=TRACE