Java 自动接线异常。无法自动关联字段
我正在使用SpringMVC和Hibernate插入数据库,但我遇到了自动连接错误 获取dis error-java.lang.ClassNotFoundException:org.aspectj.util.PartialOrder$PartialComparable 这是我的dispatcher-servlet.xml: 我无法注入bean会话工厂、注册DAO、注册服务bean 刀类Java 自动接线异常。无法自动关联字段,java,spring,Java,Spring,我正在使用SpringMVC和Hibernate插入数据库,但我遇到了自动连接错误 获取dis error-java.lang.ClassNotFoundException:org.aspectj.util.PartialOrder$PartialComparable 这是我的dispatcher-servlet.xml: 我无法注入bean会话工厂、注册DAO、注册服务bean 刀类 package com.cts.Services; import org.s
package com.cts.Services;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cts.Dao.RegistrationDao;
@Service
public class RegistrationServiceImpl implements RegistrationService
{
@Autowired
RegistrationDao regdao;
@Override
public int RegisterUser()
{
return 0;
}
}
我得到的错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registrationController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.cts.Services.RegistrationService com.cts.Controller.RegistrationController.regService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registrationServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.cts.Dao.RegistrationDao com.cts.Services.RegistrationServiceImpl.regdao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registrationDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.h2.engine.SessionFactory com.cts.Dao.RegistrationDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.h2.engine.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:598)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:661)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:517)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.cts.Services.RegistrationService com.cts.Controller.RegistrationController.regService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registrationServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.cts.Dao.RegistrationDao com.cts.Services.RegistrationServiceImpl.regdao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registrationDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.h2.engine.SessionFactory com.cts.Dao.RegistrationDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.h2.engine.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
... 29 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registrationServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.cts.Dao.RegistrationDao com.cts.Services.RegistrationServiceImpl.regdao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registrationDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.h2.engine.SessionFactory com.cts.Dao.RegistrationDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.h2.engine.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:876)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 31 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.cts.Dao.RegistrationDao com.cts.Services.RegistrationServiceImpl.regdao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registrationDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.h2.engine.SessionFactory com.cts.Dao.RegistrationDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.h2.engine.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
... 42 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registrationDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.h2.engine.SessionFactory com.cts.Dao.RegistrationDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.h2.engine.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
您没有包含RegistrationDaoImpl的代码,但是在深入研究堆栈跟踪之后,您是否可能在RegistrationDaoImpl中导入了错误的SessionFactory类?堆栈跟踪表明RegistrationDaoImpl需要一个org.h2.engine.SessionFactory,我希望它需要一个org.hibernate.SessionFactory。尝试在RegistrationDaoImpl中修复SessionFactory的导入,看看这是否解决了您的问题 堆栈跟踪的相关部分: 创建名为“registrationDaoImpl”的bean时出错:注入 自动连线依赖失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法 autowire字段:org.h2.engine.SessionFactory com.cts.Dao.RegistrationDaoImpl.sessionFactory;嵌套异常是 org.springframework.beans.factory.noSuchBean定义异常:否 为找到类型为[org.h2.engine.SessionFactory]的匹配bean 依赖项:至少需要1个符合autowire条件的bean 此依赖项的候选项 替换
import org.h2.engine.SessionFactory;
由此
import org.hibernate.SessionFactory;
解析SessionFactory导入后,您似乎缺少aspectjweaver库。 你可以得到它 如果您使用的是maven:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.7</version>
</dependency>
请您重新阅读这个问题并改进一下格式好吗?没有得到您的答案请解释请包括java代码,包括RegistrationDaoImpl.session工厂的导入语句错误已解决bt仍然获得RegistrationService和Registration DAO未自动连线包括新StackTrace您似乎缺少aspectjweaver库。添加这个库,您是否使用maven?Spring AOP实现,我认为是重用aspectj weaver中的一些类。
import org.hibernate.SessionFactory;
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.7</version>
</dependency>