配置SpringMVC,报错:c-attribute.3: The value ‘/hello‘ of attribute ‘id‘ on element ‘bean‘ is not valid...

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">   即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值