在动态web项目(Dynamic Web Project)中,使用SpringMVC框架,新建Spring的配置文件springmvc.xml,添加扫描控制器

<context:component-scan base-package="com.bwlu.controller"/>

显示红线

元素 "context:component-scan" 的前缀 "context" 未绑定的解决方案

此时启动tomcat显示如下错误,元素 "context:component-scan" 的前缀 "context" 未绑定

元素 "context:component-scan" 的前缀 "context" 未绑定的解决方案

解决方案:

1、在springmvc.xml中添加context的声明,添加后红线消失

元素 "context:component-scan" 的前缀 "context" 未绑定的解决方案

此时启动tomcat,显示如下错误:通配符的匹配很全面, 但无法找到元素 'context:component-scan' 的声明。

元素 "context:component-scan" 的前缀 "context" 未绑定的解决方案

2、在xsi:schemaLocation实例中引用模式文档,指出模式文档的位置

元素 "context:component-scan" 的前缀 "context" 未绑定的解决方案

完整代码如下:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 6     http://www.springframework.org/schema/beans/spring-beans.xsd
 7     http://www.springframework.org/schema/context  
 8     http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 9     <!-- 扫描器 -->
10     <context:component-scan base-package="com.bwlu.controller"/>
11     <!-- 视图解析器 解析jsp视图 默认使用JSTL标签 -->
12     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
13         <!-- 配置jsp路径的前缀 -->
14         <property name="prefix" value="/WEB-INF/views/" />
15         <!-- 配置jsp路径的后缀 -->
16         <property name="suffix" value=".jsp" />
17     </bean>
18 </beans>

 

相关文章:

  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2021-08-22
  • 2022-12-23
  • 2021-10-30
猜你喜欢
  • 2021-11-05
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2021-05-02
  • 2022-02-14
相关资源
相似解决方案