首页  >  问答  >  正文

java - springmvc 解析spring*.xml配置文件的异常

刚开始接触springmvc

目标:识别基于注解的控制器类(controller)


过程如下:

 1.编写注解的controller
 2.在spring*.xml文件中配置
 <context:component-scan base-package="idv.song.controller"/>
 3.重新编译,[重启tomcat]
 4.报错如下

严重: Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/config/springmvc-config.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource


报错中加粗的部分都百度[木得google]过了,没有合适的答案


自我分析如下:

-- bean没有实例化
-- 配置文件中bean配置的错误(我的配置文件中只有关于识别注解控制器的配置)
--| 尝试去掉<context:component-scan base-package="idv.song.controller"/> -- 编译正常(dispatcherServlet.init()成功)|
--|base-package没有写错,是不是xml的语法错误或者引用content.xsd版本问题?

问题:识别注解控制器的spring配置文件的正确写法&分析我的问题


`<?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx" 
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:util="http://www.springframework.org/schema/util" 
   xmlns:jdbc="http://www.springframework.org/schema/jdbc"
   xmlns:cache="http://www.springframework.org/schema/cache"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
">
 <context:component-scan base-package="idv.song.controller"/>

<!-- register beans that support the controllers that have annotated method -->
<!--     <mvc:annotation-driven></mvc:annotation-driven>
<mvc:resources location="/" mapping="/*.html"></mvc:resources>     -->
 <!--  <bean id="/product_input" class="idv.song.controller.InputProductController"></bean>
<bean id="/product_save"  class = "idv.song.controller.SaveProductController"></bean> -->
  <bean id="veiwResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/jsp/"></property>
      <property name="suffix" value=".jsp"></property>
  </bean></beans>`
PHP中文网PHP中文网2741 天前728

全部回复(1)我来回复

  • 怪我咯

    怪我咯2017-04-18 10:25:24

    NoClassDefFoundError 说明类没有找到,看看依赖的包是否缺少spring-aop-*.jar aopalliance-1.0.jar

    回复
    0
  • 取消回复