org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [beans.xml] Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.clearCache()V at org.springframework.context.support.AbstractApplicationContext.resetCommonCaches(AbstractApplicationContext.java:924) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:575) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85) at MyTest.main(MyTest.java:13)
ApplicationContext context = new ClassPathXmlApplicationContext("userbeans.xml");
同时使用p命名空间、c命名空间
同时使用p命名空间、c命名空间,因为类中缺少无参构造器,控制台会报错:
1 2 3 4
org.springframework.context.support.AbstractApplicationContext refresh 警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'user' defined in class path resource [userbeans.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.melodyhub.pojo.User]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.melodyhub.pojo.User.<init>()
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'user' defined in class path resource [userbeans.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.melodyhub.pojo.User]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.melodyhub.pojo.User.<init>()