Не удалось инициализировать контекст org.springframework.beans.factory.BeanDefinitionStoreException: Не удалось прочитать класс компонента-кандидата: файл - PullRequest
0 голосов
/ 05 ноября 2019

получение этого исключения, следующие: dispatcher-servlet.xml и HelloController.java

error.log

INFO: Initializing Spring FrameworkServlet 'dispatcher'
[INFO] FrameworkServlet 'dispatcher': initialization started
[INFO] Refreshing WebApplicationContext for namespace 'dispatcher- 
servlet': startup date [Tue Nov 05 14:47:57 IST 2019]; root of context 
hierarchy
[INFO] Loading XML bean definitions from ServletContext resource [/WEB- 
INF/dispatcher-servlet.xml]
[INFO] JSR-250 'javax.annotation.ManagedBean' found and supported for 
component scanning
[ERROR] Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to 
read candidate component class: file [C:\Users\siddharth\october-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\SpringWebService_Client\WEB-INF\classes\controller\HelloController.class]; nested exception is java.lang.IllegalArgumentException
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:281)
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)
at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)

dispatcher-servlet.xml

<?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:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:tx="http://www.springframework.org/schema/tx"

    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

 <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
    <context:component-scan base-package="controller" />
    <mvc:annotation-driven />

<bean id ="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandler" >
    <property name="mappings">
        <props>
            <prop key="index.html">indexController</prop>
        </props>        
    </property>
</bean>

<bean   id ="viewResolver" class="org.springframework.web.servlet.view.InternalViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /> 

<bean   id ="indexController" class="org.springframework.web.servlet.mvc.ParameterizableViewController" p:viewName="index" /> 

`

HelloController.java

package controller;

import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
    @RequestMapping(value = "hello")
public class HelloController 
{
     @RequestMapping(method=RequestMethod.GET)
public String index() 
{
    return "index";
}
}
...