Exception encountered during context initialization ; No default constructor found; nested exception
2020-07-26 14:08
357 查看
问题
七月 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>()
解决
如果写了有参构造函数就会不存在默认构造函数,需要手动创建无参构造函数。
相关文章推荐
- Spring AOP 报错 Exception encountered during context initialization - cancelling refresh attempt[已解决]
- Exception encountered during context initialization - cancelling refresh attempt: org.springframewor
- Exception encountered during context initialization - cancelling refresh attempt: org.springframewor
- Exception encountered during context initialization - cancelling refresh attempt
- Java ssm报错:No default constructor found; nested exception is java.lang.NoSuchMethodException
- 警告: Exception encountered during context initialization - cancelling refresh attempt:
- Error occurred during initialization of boot layer java.lang.module.FindException: Module no found
- spring No default constructor found; nested exception is java.lang.NoSuchMethodException: com.slj.mo
- 警告: Exception encountered during context initialization - cancelling refresh attempt org.springframe
- Failed to instantiate No default constructor found; nested exception is java.lang.NoSuchMethodExcept
- 警告: Exception encountered during context initialization - cancelling refresh attempt: org.springfram
- Exception encountered during context initialization - cancelling refresh attempt
- akka创建actor时报错:IllegalArgumentException: no matching constructor found on class $iwC$$iwC$$iwC$$iwC$
- tomcat启动出现 encountered during context initialization - cancelling refresh attempt异常
- 使用Spring报错:No default constructor found
- Kotlin - com.alibaba.fastjson.JSONException: default constructor not found
- SpringBoot 集成Kotlin : org.hibernate.InstantiationException: No default constructor for entity: : com.easy.kotlin.entity.People
- org.xml.sax.SAXParseException:no declaration can be found for element 'context:component-scan'
- akka创建actor时报错:IllegalArgumentException: no matching constructor found on class $iwC$$iwC$$iwC$$iwC$
- 【SpringBoot】“没有默认的构造器”,No default constructor found;