• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

org.springframework.web.servlet.DispatcherServlet - Context initialization failed

 
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello;

This problem I do not face it when running my application at eclipse, but I faced this error when deploying the war file on the tomcat server (apache-tomcat-8.0.33), it seems it is related to the componentscan and autowire, but I am not able to know the reason exactly and how to resolve it:

ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'formController': Unsatisfied dependency expressed through field 'formServices'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.airtel.siva.services.FormServices' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}



Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.airtel.siva.services.FormServices' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}



Actually, in the FormController Class I have the following code:



In the servlet-context.xml:


<context:component-scan base-package="com.airtel.siva.Controllers" />
<context:component-scan base-package="com.airtel.siva.Services" />



While FormController Class is located under package: package com.airtel.siva.Controllers;

Moreover, the FormController Class and the FormServices Class are annotated as following:





As you see, FormServices is class and not interface and it is annotated by @Service while FormController is annotated by @Component, but the strange that it worked with me when running the application from eclipse and gave me the error while deploying the war file.

So what could be the reason for this and why it appeared only when deploying the war file?

Do I have to add ComponentScan at some place and I am missing this? Or I have to do another annotation to be able to use @Autowire for FormService class in the FormController class?

Regards
Bilal
 
Bilal Ghayad
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem resolved.

The reason of the problem was in the line <context:component-scan base-package="com.airtel.siva.Services" /> which is in the servlet-context.xml, the package name should be com.airtel.siva.services instead of Services.
Case sensitive is not effecting in microsoft windows but it is effecting in unix and the deployment was in the unix.

Regards
Bilal
 
I've been selected to go to the moon! All thanks to this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!