线程 "main" java.lang.ClassCastException 中的异常:
org.springframework.beans.factory.xml.XmlBeanFactory 不能强制转换为 org.springframework.beans.factory.BeanFactory at com.ashish.Test.main(Test.java:11(
如何解决此异常?即使在铸造之后,我也得到了同样的例外。
您可以尝试以下操作
XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
但是,建议使用ApplicationContext
因为它提供的不仅仅是豆厂更多的好处。
context = new ClassPathXmlApplicationContext("applicationContext.xml");
Student student=(Student)factory.getBean("studentbean");