![](/img/trans.png)
[英]Where should I implement specific queries in mvc architecture(spring + hibernate)?
[英]Where should I write my Spring MVC configuration class in a n-tiers architecture in a Maven project?
我正在嘗試使用Spring
和Spring-MVC
在n-tiers
Web應用程序中練習我學到的東西。 但我發現做正確配置有困難。
所以我正在使用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)}
謝謝你的時間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.