18

以下是我在其它论坛上发表的问题:


QUOTE:
我采用AbstractDependencyInjectionSpringContextTests进行测试,通过以下代码进行加载.
       protected String[] getConfigLocations() {                return new String[] { "classpath:springapplicationcontext.xml" };        }
以下是我原来的配置文件:
<?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>
       <bean id="dataSource"
               class="org.apache.commons.dbcp.BasicDataSource">
               <property name="driverClassName">
                       <value>oracle.jdbc.driver.OracleDriver</value>
字串1

               </property>
               <property name="url">
                       <value>jdbc:oracle:thin:@localhost:1521:oracle9</value>
               </property>
               <property name="username">
                       <value>gap</value>
               </property>
               <property name="password">
                       <value>gap</value>
               </property>
       </bean> 字串3
       <bean id="sessionFactory"
               class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
               <property name="dataSource" ref="dataSource" />
               <property name="configLocation">
                       <value>classpath:hibernate.cfg.xml</value>
               </property>
       </bean>
       <bean id="txManager"
               class="org.springframework.orm.hibernate3.HibernateTransactionManager">
               <property name="sessionFactory" ref="sessionFactory" /> 字串9
       </bean>
       <bean id="gapdictionaryDao" class="org.gap.dao.GapdictionaryDao">
               <property name="sessionFactory">
                       <ref bean="sessionFactory" />
               </property>
       </bean>
       <bean id="gap" class="org.gap.service.GapImpl">
               <property name="gapdictionaryDao" ref="gapdictionaryDao" />
       </bean>
</beans>

以下是我新的配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 字串9
       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.0.xsd           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> 字串3
       <bean id="dataSource"
               class="org.apache.commons.dbcp.BasicDataSource">
               <property name="driverClassName">
                       <value>oracle.jdbc.driver.OracleDriver</value>
               </property>
               <property name="url">
                       <value>jdbc:oracle:thin:@localhost:1521:oracle9</value>
               </property>
               <property name="username">
                       <value>gap</value> 字串2
               </property>
               <property name="password">
                       <value>gap</value>
               </property>
       </bean>
       <!–                <bean id="dataSource"                class="org.springframework.jndi.JndiObjectFactoryBean">                <property name="jndiName">                <value>gappool</value>                </property>                </bean>        –>
字串6

       <bean id="sessionFactory"
               class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
               <property name="dataSource" ref="dataSource" />
               <property name="configLocation">
                       <value>classpath:hibernate.cfg.xml</value>
               </property>
       </bean>
       <bean id="txManager"
               class="org.springframework.orm.hibernate3.HibernateTransactionManager">
               <property name="sessionFactory" ref="sessionFactory" />
字串8


       </bean>
       <aop:config>
               <aop:pointcut id="gapServiceMethods"
                       expression="execution(* org.gap.service.*Service.*(..))" />
               <aop:advisor advice-ref="txAdvice"
                       pointcut-ref="gapServiceMethods" />
       </aop:config>
       <tx:advice id="txAdvice" transaction-manager="txManager">
               <tx:attributes>
                       <tx:method name="saveOrUpdate*" propagation="REQUIRED" />
字串7

                       <tx:method name="delete*" propagation="REQUIRED" />
                       <tx:method name="handle*" propagation="REQUIRED" />
                       <tx:method name="*" propagation="SUPPORTS" read-only="true" />
               </tx:attributes>
       </tx:advice>
       <bean id="gapdictionaryDao" class="org.gap.dao.GapdictionaryDao">
               <property name="sessionFactory">
                       <ref bean="sessionFactory" /> 字串2
               </property>
       </bean>
       <bean id="gap" class="org.gap.service.GapImpl">
               <property name="gapdictionaryDao" ref="gapdictionaryDao" />
       </bean>
</beans>


用原来的配置文件,可以顺利通过测试,改用新的后,就报以下错:
org.springframework.beans.factory.BeanDefinitionStoreException: Line 14 in XML document from class path resource [springapplicationcontext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.  

在matrix上问了,没人理.在CSDN上问了,也没人理.在javaeye上问了,还扣掉了我10分,说这是新手才问的问题。可能在他们看来,所有和配置有关的问题都是只有新手才问的。不管它。 字串3

在求人不能后,终于在google上找到了一篇文章,是spring的官方论坛上的一个高手给一个新手的解答。
有兴趣的可以看看,
http://forum.springframework.org/showthread.php?t=37877
主要原因就是在classpath里还有以前spring老版本的jar包,而采用以上新配置文件的写法,则只能用于spring2.x的版本。这种新的写法对于有大量方法和类需要配置事务的系统可以节省很多时间。去掉以前版本的jar后就可以了。

真是求人不如求已。

一些网站真是店大欺客啊。



欢迎转载,请注明转载自[分享文档]


Tags: ,

作者:Jock

One Response to “使用spring2.0.5配置事务时出现关于配置文件报错问题的解决办法zz”

  1. jock Says:

    看来还有很长的路要走啊

Leave a Reply

You must be logged in to post a comment.

Switch to our mobile site