赞
踩
七月 26, 2020 2:05:03 下午 org.springframework.context.support.AbstractApplicationContext refresh 警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [bean.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.wei.service.impl.UserServiceImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.wei.service.impl.UserServiceImpl.<init>() Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [bean.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.wei.service.impl.UserServiceImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.wei.service.impl.UserServiceImpl.<init>() at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1320) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1214) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:893) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85) at Client.main(Client.java:15) Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.wei.service.impl.UserServiceImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.wei.service.impl.UserServiceImpl.<init>() at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1312) ... 13 more Caused by: java.lang.NoSuchMethodException: com.wei.service.impl.UserServiceImpl.<init>() at java.lang.Class.getConstructor0(Class.java:3082) at java.lang.Class.getDeclaredConstructor(Class.java:2178) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78) ... 14 more Process finished with exit code 1
该异常的重点在于这句。没有默认构造函数。
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.wei.service.impl.UserServiceImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.wei.service.impl.UserServiceImpl.<init>()
如果写了有参构造函数就会不存在默认构造函数,需要手动创建无参构造函数。
如果有帮助到你,希望可以点个赞!谢谢!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。