`
xiexd
  • 浏览: 245547 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

SPRING配置问题

阅读更多

问:Spring 2.0,使用<aop:config>来配置AOP

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

<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"
>
</beans>


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

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

但如果删掉<beans>中的那些,我就无法在<beans>里使用<aop:config>这些元素来配置

 

答:配置的spring的文件和 引入的spring 的jar包的版本不一致!
最好的方法是: 根据下载的spring 导入对应的jar包 然后配置xml文件的时候,从其例子里面拷贝其配置信息,就可以了!比如我引入的jar包 是2.5.6 我直接从下载的jpetstore例子中抽取配置文件头信息就可以了
下面的配置信息:
<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">

需引入spring.jar 2.5.6版本

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics