SpringデータsolrとSpring mvcを混在させるときに問題が発生します。単にspringデータsolrを使用すると、すべてが正常に実行されますが、spring mvcをintergrateするようになりました。Spring mvcの設定に関する問題を見ました。SpringデータsolrとSpring mvcをintergrateする方法
リポジトリクラス:
public class ManufacturerRepositoryImpl implements ManufacturerRepository{
private Logger logger = Logger.getLogger(ManufacturerRepositoryImpl.class);
@Autowired
private SessionFactory factory;
@SuppressWarnings("unchecked")
public List<Manufacturer> getAllManufacturer() {
Query query = factory.getCurrentSession().createQuery("SELECT m FROM Manufacturer m");
return query.list();
}
}
サービスクラス:
@Service
public class ManufacturerServiceImpl implements ManufacturerService {
@Autowired
private ManufacturerRepository manufacturerRepository;
public List<Manufacturer> getAllManufacturer() {
return manufacturerRepository.getAllManufacturer();
}
}
コントローラクラス:(は更新)
@Controller
public class ManagementManufacturerController {
@Autowired **// UPDATED**
private ManufacturerService manufactureService;
@RequestMapping(value="/manageManufacturer")
public String getAllManufacturers(HttpServletRequest request,
HttpServletResponse response,
ModelMap model) {
List<Manufacturer> manuList = manufactureService.getAllManufacturer();
model.put("manuList", manuList);
return "manageManufacturer";
}
}
JSP:
<c:forEach var="renter" items="${manuList}">
<c:out value="${renter.id}" />
<c:out value="${renter.name}" />
</c:forEach> --%>
のpom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- SOLR -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>${spring-data-solr.verion}</version>
</dependency>
<!-- JSON -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.11</version>
</dependency>
<!-- WEB -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Hibernate 4 dependencies -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-commons -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.12.5.RELEASE</version>
</dependency>
</dependencies>
ログメッセージ:(更新)
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managementManufacturerController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.totoroads.service.ManufacturerService com.totoroads.data.solr.showcase.product.web.ManagementManufacturerController.manufactureService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.totoroads.service.ManufacturerService] 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:292)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:648)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:909)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:898)
at com.totoroads.data.solr.showcase.Application.main(Application.java:40)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.totoroads.service.ManufacturerService com.totoroads.data.solr.showcase.product.web.ManagementManufacturerController.manufactureService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.totoroads.service.ManufacturerService] 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:508)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
... 16 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.totoroads.service.ManufacturerService] 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.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1103)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:963)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
... 18 more
2017-03-08 19:17:18.198 INFO 4716 --- [ main] utoConfigurationReportLoggingInitializer :
それは不足のサーブレットコンテキストまたは任意のファイルを思えだ、と私は春のデータをintergrateする経験していませんソルとスプリングMVC。どのように問題を解決する?ありがとうございます !
こんにちは@Dennis Ich、返信いただきありがとうございます。私はAnnotation autowiredを更新しましたが、上記のような例外が発生します –
オリジナルの質問を編集すると、情報が追加されてしまいます類似の問題でここに来るかもしれない他の人には役に立ちます:)。もう一方は私の編集を参照してください。 –
はい、これは疑問ではない私の間違いですが、あなたの解決策は私のために良いです、私はそれを試みるか、新しい質問を作成します... @Dennis Ichに感謝します –