spring mvc 一个非常奇怪的问题 百思不得其解 求点拨 谢谢

J2EE 码拜 8年前 (2016-03-19) 722次浏览
使用的是jre1.8  spring4.0   让本人百思不得其解的是只要springmvc.xml中出现了
<context:component-scan base-package=”com.ssm.controller”></context:component-scan>  这个标签 就肯定会报下面的这个错误,只要不写这个标签就能成功部署,  搞得没法进一步学习注解的相关内容  求高人看下这个到底是哪里的错误 本人实在搞不懂,多谢了!
spring mvc 一个非常奇怪的问题 百思不得其解 求点拨 谢谢

springmvc.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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            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">
   
  
 <context:component-scan base-package="com.ssm.controller"></context:component-scan>
  
 
 
  <!-- 处理器适配器 将bean的name作为url进行查找 ,需要在配置Handler时指定beanname(就是url) 
    全部的映射器都实现 HandlerMapping接口。 -->
  <bean   class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
   
   
   
      <!-- 配置Handler  将编写的Handller在映射器加载 ,name一定要写成url -->
    <bean  id="itemsController" name="/queryItems.action" class="com.ssm.controller.ItemsController1" />
     
     
    <!-- 处理器映射器 将bean的name作为url进行查找 ,需要在配置Handler时指定beanname(就是url) 
    全部的映射器都实现 HandlerMapping接口。
    -->
    <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
 
 
    <!-- 视图解析器
    解析jsp解析,默认使用jstl标签,classpath下的得有jstl的包
     -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
     
    </bean>
</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>springmvc</display-name>
   
  <!-- springmvc前端控制器 -->
  <servlet>
      <servlet-name>springmvc</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       
      <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath:springmvc.xml</param-value>
      </init-param>
  </servlet>
   
  <servlet-mapping>
      <servlet-name>springmvc</servlet-name>
   
      <url-pattern>*.action</url-pattern>
  </servlet-mapping>
   
   
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

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<Items> itemsList = new ArrayList<Items>();
                //向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;
 
    }
 
}
解决方案

37

引用:
Quote: 引用:

你这个异常可能是Spring在提取注解信息时的异常,你看下”com.ssm.controller”这个包下 你有没有用到什么注解,先把注解注释掉,然后再试试。假如没问题,再把注解放出来再试

你好 本人已经用注解方式写了一遍 还是报错 在8楼里面贴了代码

你既然Web.xml配置了
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
那你的applicationContext.xml 呢?贴出来看看


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明spring mvc 一个非常奇怪的问题 百思不得其解 求点拨 谢谢
喜欢 (0)
[1034331897@qq.com]
分享 (0)