• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

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

 
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 56
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic