java - spring mvc 只要使用context:component-scan标签就报500错误

 书友51676198 发布于 2022-10-29 03:56

使用的是jre1.8 spring4.0 让我百思不得其解的是只要springmvc.xml中出现了
这个标签 就肯定会报下面的这个500错误,只要不写这个标签就能成功部署,我后来用标注的方式来标记handler还是不行 一切都是因为这个标签的问题 已经好几天了无法解决 求高人看下这个到底是哪里的错误 我实在搞不懂,多谢了!

springmvc.xml 配置文件


http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/aop 
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/mvc 
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
   
 
   
  
  
  
  
    
    
    
      
    
      
      
    
    
  
  
    
    
      
    







web.xml

 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  springmvc
    
  
  
      springmvc
      org.springframework.web.servlet.DispatcherServlet
        
      
          contextConfigLocation
          classpath:springmvc.xml
      
  
    
  
      springmvc
    
      *.action
  
    
    
  
    index.html
    index.htm
    index.jsp
    default.html
    default.htm
    default.jsp
  





**ItemsController1**

    package com.ssm.controller;
  
import java.util.ArrayList;
import java.util.List;
  
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
  
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
  
import com.ssm.pojo.Items;
  
public class ItemsController1 implements Controller{
  
      
    public ModelAndView handleRequest(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
          
        //调用service查找 数据库,查询商品列表,这里使用静态数据模拟
                List itemsList = new ArrayList();
                //向list中填充静态数据
                  
                Items items_1 = new Items();
                items_1.setName("联想笔记本");
                items_1.setPrice(6000f);
                items_1.setDetail("ThinkPad T430 联想笔记本电脑!");
                  
                Items items_2 = new Items();
                items_2.setName("苹果手机");
                items_2.setPrice(5000f);
                items_2.setDetail("iphone6苹果手机!");
                  
                itemsList.add(items_1);
                itemsList.add(items_2);
  
                //返回ModelAndView
                ModelAndView modelAndView =  new ModelAndView();
                //相当 于request的setAttribut,在jsp页面中通过itemsList取数据
                modelAndView.addObject("itemsList", itemsList);
                  
                //指定视图
                modelAndView.setViewName("/WEB-INF/jsp/items/itemsList.jsp");
  
                return modelAndView;
  
    }
  
}
4 个回答
  • 楼主,我的问题和你一模一样,弄了很久都找不到原因,你怎么解决的啊?

    2022-10-30 07:03 回答
  • 楼上正解,因为你没有在web服务器启动的时候加载spring容器。我只是多此一举掺和一下~~~~

    2022-10-30 07:06 回答
  • <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
    

    web.xml少了上面这句,把Spring容器集成到 Web 应用里面

    2022-10-30 07:07 回答
  • com.ssm.controller.*试试

    2022-10-30 07:07 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有