剛開始接觸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>`
1 回答

呼啦一陣風
TA貢獻1802條經驗 獲得超6個贊
NoClassDefFoundError 說明類沒有找到,看看依賴的包是否缺少spring-aop-*.jar aopalliance-1.0.jar
添加回答
舉報
0/150
提交
取消