【发布时间】:2019-05-16 04:01:28
【问题描述】:
我正在尝试在n-tiers 网络应用程序中练习我在@987654327@ 和Spring-MVC 中学到的知识。但是我发现在进行正确配置方面存在困难。
所以我使用Maven。到目前为止,我创建了 3 个项目。第一个负责通用的Hibernate DAO 实现。第二个是我的业务逻辑层,在那里我有我的类 DAO 和我的服务。第三个是我的控制器所在的位置。我想使用 Spring 依赖注入来管理我的服务和 DAO 实例。但是无论我把我的配置类放在哪里,我都会收到一个错误:
org.springframework.beans.factory.UnsatisfiedDependencyException
第一个项目:
第二个项目:
第三个项目:
您可能想知道为什么AppConfig 在两个项目中,这只是为了调试目的。我不知道我应该把它放在哪里。
我的AppConfig 班级:
@EnableWebMvc
@Configuration
@ComponentScan(basePackages = { "com.controllers", "com.services", "com.dao" })
public class AppConfig {
}
我的SpringMvcDispatcherInitializer 班级:
public class SpringMvcDispatcherInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return null;
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] { AppConfig.class };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}
我在Maven 服务器上运行pfa-web 项目时收到的错误:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'touristController': Unsatisfied dependency expressed through field 'touristService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'touristServiceImp': Unsatisfied dependency expressed through field 'touristDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'touristDaoImp': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.hibernate.SessionFactory' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
感谢您的宝贵时间。
【问题讨论】:
标签: java spring maven spring-mvc