biaoge2000000
biaoge2000000
2011-05-03 16:45

Spring初学者,配置出错,求解决办法。

  • spring

<?xml version="1.0" encoding="UTF-8" ?>
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/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

<!-- 配置数据源 -->
<bean id = "dataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name = "driverClass" value = "com.mysql.jdbc.Driver"/>
    <property name = "jdbcUrl" value = "jdbc:mysql://localhost/db_bbs"/>
    <property name = "user" value = "root"/>
    <property name ="password" value = "cy123"/>
    <property name = "maxPoolSize" value = "40"/>
    <property name = "minPoolSize" value = "1"/>
    <property name = "maxIdleTime" value = "20"/>
</bean>
<!-- 配置对应的事务管理器 -->
<bean id = "transactionManager" class = "org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name = "dataSource" ref = "dataSource"/>
</bean>

<!-- 配置业务逻辑BEAN -->
<bean id = "test" class = "trans.TestImp1">
    <property name = "ds" ref = "dataSource"/>
</bean>

<!-- 配置事务切面bean -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="get*" read-only="true"/>
        <tx:method name="*"/>
    </tx:attributes>
</tx:advice>

<aop:config>
    <aop:pointcut id="addTrans" expression="execution(* trans.*Imp1.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="addTrans"/>
</aop:config>   

运行时报错如下
schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/tx/spring-tx-2.5.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not xsd:schema.

Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 34 in XML document from class path resource [applicationContext.xml] is invalid; nested

exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'tx:advice'.
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'tx:advice'.

搜索了一下网上的解决办法,都是说在声明那里增加xmlns:tx声明,但我加了还是报这个错误,不知道是怎么回事了.....

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答