1、springmvc.xml文件中报错详情
Multiple annotations found at this line:
- cvc-attribute.3: The value '/hello' of attribute 'id' on element 'bean' is not valid with respect
to its type, 'ID'.
- cvc-datatype-valid.1.2.1: '/hello' is not a valid value for 'NCName'.
2、报错语句
<bean id="/hello" class="com.kuang.controller.HelloController"/>
3、springmvc.xml配置文件内容
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- 先在springmvc.xml配置文件中添加处理器映射器 -->
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<!-- 添加处理器适配器 -->
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<!-- 配置视图解析器:把handler处理类的返回值,加工成最终的视图路径-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="InternalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix" value="/WEB-INF/jsp"></property>
<!-- 后缀 -->
<property name="suffix" value=".jsp"></property>
</bean>
<!-- Handler -->
<bean id="/hello" class="com.kuang.controller.HelloController"/>
</beans>
4、解决方法
报错的代码没有写错,出错的地方在于xml文件的版本,将http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> 改为
http://www.springframework.org/schema/beans/spring-beans.xsd"> 即可。