---
title: "SPRING配置问题"
author: "xiexd"
date: "2010-09-25T17:49:14Z"
tags: ["AOP", "Bean", "Spring", "XML"]
categories: ["企业架构"]
slug: "spring"
draft: false
lastmod: "2010-09-25T17:49:14Z"
id: 771352
url: "https://parkmy.iteye.com/blog/771352"
---

问：Spring 2.0,使用&lt;aop:config&gt;来配置AOP

&lt;?xml version="1.0" encoding="UTF-8" ?&gt;  
&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"&gt;

&lt;beans xmlns="http://www.springframework.org/schema/beans"  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xmlns:aop="http://www.springframework.org/schema/aop"  
xsi:schemaLocation="http://www.springframework.org/  
schema/beans  
http://www.springframework.org/schema/beans/  
spring-beans-2.0.xsd  
http://www.springframework.org/schema/aop  
http://www.springframework.org/schema/aop/  
spring-aop-2.0.xsd" &gt;  
&lt;/beans&gt;

红色字体部分无法同时存在  
报错：Attribute "xmlns" must be declared for element type "beans".

如果删掉这个：&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"&gt;  
就会报错：cvc-elt.1: Cannot find the declaration of element 'beans'.  
因为我用的是spring 2.0

但如果删掉&lt;beans&gt;中的那些，我就无法在&lt;beans&gt;里使用&lt;aop:config&gt;这些元素来配置

 

答：配置的spring的文件和 引入的spring 的jar包的版本不一致！  
最好的方法是: 根据下载的spring 导入对应的jar包 然后配置xml文件的时候，从其例子里面拷贝其配置信息，就可以了！比如我引入的jar包 是2.5.6 我直接从下载的jpetstore例子中抽取配置文件头信息就可以了  
下面的配置信息：  
&lt;beans xmlns="http://www.springframework.org/schema/beans"  
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"  
xsi:schemaLocation="  
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"&gt;

需引入spring.jar 2.5.6版本