当前位置: 代码迷 >> 综合 >> Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springfram
  详细解决方案

Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springfram

热度:74   发布时间:2023-11-23 10:35:05.0

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘user’ defined in file [F:\workplace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\StudentManageSSM\WEB-INF\classes\com\z\entity\User.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘java.lang.Long’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory1.getObject(AbstractBeanFactory.java:306)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)atorg.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4900)atorg.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5363)atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)atorg.apache.catalina.core.ContainerBase1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4900) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5363) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) at org.apache.catalina.core.ContainerBase1.getObject(AbstractBeanFactory.java:306)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)atorg.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4900)atorg.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5363)atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)atorg.apache.catalina.core.ContainerBaseStartChild.call(ContainerBase.java:1410)
at org.apache.catalina.core.ContainerBaseStartChild.call(ContainerBase.java:1400)atjava.util.concurrent.FutureTask.run(FutureTask.java:266)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)atjava.util.concurrent.ThreadPoolExecutorStartChild.call(ContainerBase.java:1400) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutorStartChild.call(ContainerBase.java:1400)atjava.util.concurrent.FutureTask.run(FutureTask.java:266)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)atjava.util.concurrent.ThreadPoolExecutorWorker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘java.lang.Long’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
… 24 more
一开始是去service层查找有没有加@Service,发现service接口和实现类都加了,没毛病,接着又去dao层,dao层加了@Repository,mapper配置路径也没有问题,找了老久了,结果实体类重写了一遍,迷之尴尬的好了。发现空参构造没写,只写了实参构造,导致无参构造被覆盖,给你们个小建议,实体类要写就写全了,不差那么点时间,以免报错找半天

  相关解决方案