Error org springframework web servlet dispatcherservlet context initialization failed

ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed. So what could be the reason for this and why it appeared only when deploying the war file?.


posted 2 years ago

  • 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

Below is the exception that I have received when I am integrating the tiles 3.0 framework with Spring 4.0 web mvc application. Using the solution below I have rectified the issue my self. Hope this is useful to all.

21:02:06,311 ERROR [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool — 74) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ’tilesConfigurer’ defined in ServletContext resource [/config/spring-context.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.apache.tiles.access.TilesAccess.setContainer(Lorg/apache/tiles/request/ApplicationContext;Lorg/apache/tiles/TilesContainer;Ljava/lang/String;)V
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) [spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) [spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) [spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) [spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) [spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) [spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) [spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) [spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) [spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) [spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658) [spring-webmvc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624) [spring-webmvc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672) [spring-webmvc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543) [spring-webmvc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484) [spring-webmvc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) [spring-webmvc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1194) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1100) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3591) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3798) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156) [jboss-as-web-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60) [jboss-as-web-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93) [jboss-as-web-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [rt.jar:1.8.0]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.8.0]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: java.lang.NoSuchMethodError: org.apache.tiles.access.TilesAccess.setContainer(Lorg/apache/tiles/request/ApplicationContext;Lorg/apache/tiles/TilesContainer;Ljava/lang/String;)V
at org.apache.tiles.startup.AbstractTilesInitializer.initialize(AbstractTilesInitializer.java:65) [tiles-core-3.0.4.jar:3.0.4]
at org.springframework.web.servlet.view.tiles3.TilesConfigurer.afterPropertiesSet(TilesConfigurer.java:270) [spring-webmvc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) [spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) [spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
… 29 more

Solution:

step 1: Check the spring tiles configuration: DTD should match with the version of jars added into application

<?xml version=”1.0″ encoding=”UTF-8″ ?>
<!DOCTYPE tiles-definitions PUBLIC
-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN”
“http://tiles.apache.org/dtds/tiles-config_3_0.dtd”&gt;

<tiles-definitions>
<definition name=”base.definition” template=”/jsp/layout.jsp”>
<put-attribute name=”title” value=”” />
<put-attribute name=”header” value=”/jsp/header.jsp” />
<put-attribute name=”menu” value=”/jsp/menu.jsp” />
<put-attribute name=”body” value=”” />
<put-attribute name=”footer” value=”/jsp/footer.jsp” />
</definition>

<definition name=”contact” extends=”base.definition”>
<put-attribute name=”title”
value=”Sample Spring MVC With Tiles Appliacation” />
<put-attribute name=”body” value=”/jsp/contact.jsp” />
</definition>

</tiles-definitions>

Step 2: Check the spring configuration files: DTD should match to the jars added into application

<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:mvc=”http://www.springframework.org/schema/mvc”
xmlns:context=”http://www.springframework.org/schema/context”
xsi:schemaLocation=”
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd“>

<context:component-scan base-package=”in.javatutorials.spring.controller” />
<mvc:annotation-driven />
<bean id=”viewResolver” class=”org.springframework.web.servlet.view.UrlBasedViewResolver“>
<property name=”viewClass” value=”org.springframework.web.servlet.view.tiles3.TilesView“/>
</bean>

<bean id=”tilesConfigurer” class=“org.springframework.web.servlet.view.tiles3.TilesConfigurer“>
<property name=”definitions”>
<list>
<value>/config/tiles.xml</value>
</list>
</property>
</bean>

</beans>

Step 3: Check the jar versions with the above DTD versions:

Spring4 and Tiles 3 Integration Jars

Я разрабатываю проект Roo и развертываю его на сервере Tomcat 6. До сих пор все работало нормально.

Я удалил и снова добавил сущность.

Теперь каждый раз, когда я запускаю Tomcat, я получаю это исключение в Spring Tool Suite:

SEVERE: StandardWrapper.Throwable
Throwable occurred: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.MappedInterceptor#0': Cannot create inner bean '(inner bean)' of type [org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'applicationConversionService' while setting constructor argument; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [myproject.web.ApplicationConversionServiceFactoryBean] for bean with name 'applicationConversionService' defined in ServletContext resource [/WEB-INF/spring/webmvc-config.xml]; nested exception is java.lang.ClassNotFoundException: myproject.web.ApplicationConversionServiceFactoryBean
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [myproject.web.ApplicationConversionServiceFactoryBean] for bean with name 'applicationConversionService' defined in ServletContext resource [/WEB-INF/spring/webmvc-config.xml]; nested exception is java.lang.ClassNotFoundException: myproject.web.ApplicationConversionServiceFactoryBean
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
...

Что мне нужно сделать, чтобы он снова заработал?

5 ответы

spring жалуется на то, что bean-компонент недоступен (вероятно, тот, который вы сказали, что удалили).

 exception is java.lang.ClassNotFoundException: myproject.web.ApplicationConversionServiceFactoryBean

попробуйте найти файлы конфигурации xml и удалить ссылку на этот класс, после этого все должно вернуться,

Создан 29 июля ’11, 02:07

У меня была точно такая же проблема. Проблема заключалась в том, что я отключил функцию «Проект > Автоматическая сборка», поэтому мне пришлось вручную собирать проект. Как только я вручную построил проект, все вернулось в норму. :)

Поэтому не забудьте собрать проект перед его развертыванием или просто снова включите функцию «Проект > Автоматическая сборка».

Надеюсь, поможет.

Создан 09 янв.

Ваше приложение, развернутое на Tomcat, не имеет JAR-файла в WEB-INF/lib, содержащего класс myproject.web.ApplicationConversionServiceFactoryBean. Я не знаю, что это за класс и где его найти, но его нет.

Создан 28 июля ’11, 21:07

мой обходной путь (работал с eclipse и roo 1.1.5 как плагин eclipse)

  • открыть класс ApplicationConversionServiceFactoryBean.java
  • удалить аннотацию класса @RooConversionService
  • ждите обновления ру
  • добавить обратно аннотацию класса @RooConversionService
  • дождитесь обновления roo и повторите попытку

Создан 13 сен.

Внутри STS щелкните ->project->clean. Он очищает и отбрасывает все проблемы сборки и состояния сборки. В следующий раз, когда произойдет сборка, проекты будут перестроены с нуля.

ответ дан 10 апр.

Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками

java
spring
tomcat
spring-roo

or задайте свой вопрос.

Понравилась статья? Поделить с друзьями:
  • Error org lwjgl lwjglexception pixel format not accelerated
  • Error ordinal expression expected паскаль
  • Error orcad 15052
  • Error oracle ora 00257 archiver error
  • Error ora 28001 the password has expired