获取此异常,以下是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";
}
}