论坛首页 入门技术论坛

大家帮我看看,spring的配置文件哪里有问题?

浏览 3882 次
该帖已经被评为新手帖
作者 正文
   发表时间:2007-05-10  

我采用AbstractDependencyInjectionSpringContextTests进行测试,通过以下代码进行加载.

java 代码
  1. protected String[] getConfigLocations() {   
  2.     return new String[] { "classpath:springapplicationcontext.xml" };   
  3. }  


以下是我原来的配置文件:

xml 代码
  1. <!---->xml version="1.0" encoding="utf-8"?>  
  2. <!---->>  
  3. <beans>  
  4.   
  5.  <bean id="dataSource"  
  6.   class="org.apache.commons.dbcp.BasicDataSource">  
  7.   <property name="driverClassName">  
  8.    <value>oracle.jdbc.driver.OracleDrivervalue>  
  9.   property>  
  10.   <property name="url">  
  11.    <value>jdbc:oracle:thin:@localhost:1521:oracle9value>  
  12.   property>  
  13.   <property name="username">  
  14.    <value>gapvalue>  
  15.   property>  
  16.   <property name="password">  
  17.    <value>gapvalue>  
  18.   property>  
  19.  bean>  
  20.   
  21.  <!---->
  22.   <bean id="dataSource"  
  23.   class="org.springframework.jndi.JndiObjectFactoryBean">  
  24.   <property name="jndiName">  
  25.   <value>gappoolvalue>  
  26.   property>  
  27.   bean>  
  28.  -->  
  29.  <bean id="sessionFactory"  
  30.   class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  31.   <property name="dataSource" ref="dataSource" />  
  32.   <property name="configLocation">  
  33.    <value>classpath:hibernate.cfg.xmlvalue>  
  34.   property>  
  35.      
  36.  bean>  
  37.  <bean id="txManager"  
  38.   class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  39.   <property name="sessionFactory" ref="sessionFactory" />  
  40.  bean>  
  41.  <bean id="gapdictionaryDao" class="org.gap.dao.GapdictionaryDao">  
  42.   <property name="sessionFactory">  
  43.    <ref bean="sessionFactory" />  
  44.   property>  
  45.  bean>  
  46.  <bean id="gap" class="org.gap.service.GapImpl">  
  47.   <property name="gapdictionaryDao" ref="gapdictionaryDao" />  
  48.  bean>  
  49. beans>  
  50.   

 

以下是我新的配置文件:

 

 

 

xml 代码
  1. <!---->xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.  xmlns:aop="http://www.springframework.org/schema/aop"  
  5.  xmlns:tx="http://www.springframework.org/schema/tx"  
  6.  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd   
  7.            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd   
  8.            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">  
  9.  <bean id="dataSource"  
  10.   class="org.apache.commons.dbcp.BasicDataSource">  
  11.   <property name="driverClassName">  
  12.    <value>oracle.jdbc.driver.OracleDrivervalue>  
  13.   property>  
  14.   <property name="url">  
  15.    <value>jdbc:oracle:thin:@localhost:1521:oracle9value>  
  16.   property>  
  17.   <property name="username">  
  18.    <value>gapvalue>  
  19.   property>  
  20.   <property name="password">  
  21.    <value>gapvalue>  
  22.   property>  
  23.  bean>  
  24.   
  25.  <!---->
  26.   <bean id="dataSource"  
  27.   class="org.springframework.jndi.JndiObjectFactoryBean">  
  28.   <property name="jndiName">  
  29.   <value>gappoolvalue>  
  30.   property>  
  31.   bean>  
  32.  -->  
  33.  <bean id="sessionFactory"  
  34.   class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  35.   <property name="dataSource" ref="dataSource" />  
  36.   <property name="configLocation">  
  37.    <value>classpath:hibernate.cfg.xmlvalue>  
  38.   property>  
  39.   
  40.  bean>  
  41.  <bean id="txManager"  
  42.   class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  43.   <property name="sessionFactory" ref="sessionFactory" />  
  44.  bean>  
  45.  <aop:config>  
  46.   <aop:pointcut id="gapServiceMethods"  
  47.    expression="execution(* org.gap.service.*Service.*(..))" />  
  48.   <aop:advisor advice-ref="txAdvice"  
  49.    pointcut-ref="gapServiceMethods" />  
  50.  aop:config>  
  51.   
  52.  <tx:advice id="txAdvice" transaction-manager="txManager">  
  53.   <tx:attributes>  
  54.    <tx:method name="saveOrUpdate*" propagation="REQUIRED" />  
  55.    <tx:method name="delete*" propagation="REQUIRED" />  
  56.    <tx:method name="handle*" propagation="REQUIRED" />  
  57.    <tx:method name="*" propagation="SUPPORTS" read-only="true" />  
  58.   tx:attributes>  
  59.  tx:advice>  
  60.   
  61.  <bean id="gapdictionaryDao" class="org.gap.dao.GapdictionaryDao">  
  62.   <property name="sessionFactory">  
  63.    <ref bean="sessionFactory" />  
  64.   property>  
  65.  bean>  
  66.  <bean id="gap" class="org.gap.service.GapImpl">  
  67.   <property name="gapdictionaryDao" ref="gapdictionaryDao" />  
  68.  bean>  
  69. beans>  
  70.   


用原来的配置文件,可以顺利通过测试,改用新的后,就报以下错:

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'.
 at weblogic.apache.xerces.parsers.DOMParser.parse(DOMParser.java:271)
 at weblogic.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:201)
 at weblogic.xml.jaxp.RegistryDocumentBuilder.parse(RegistryDocumentBuilder.java:149)
 at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:76)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:145)
 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:99)
 at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:102)
 at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:70)
 at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:87)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:262)
 at org.springframework.context.support.ClassPathXmlApplicationContext.<init></init>(ClassPathXmlApplicationContext.java:80)
 at org.springframework.context.support.ClassPathXmlApplicationContext.<init></init>(ClassPathXmlApplicationContext.java:65)
 at org.springframework.test.AbstractSpringContextTests.loadContextLocations(AbstractSpringContextTests.java:113)
 at org.springframework.test.AbstractDependencyInjectionSpringContextTests.loadContextLocations(AbstractDependencyInjectionSpringContextTests.java:147)
 at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:95)
 at org.springframework.test.AbstractDependencyInjectionSpringContextTests.setUp(AbstractDependencyInjectionSpringContextTests.java:114)
 at junit.framework.TestCase.runBare(TestCase.java:125)
 at junit.framework.TestResult$1.protect(TestResult.java:106)
 at junit.framework.TestResult.runProtected(TestResult.java:124)
 at junit.framework.TestResult.run(TestResult.java:109)
 at junit.framework.TestCase.run(TestCase.java:118)
 at junit.framework.TestSuite.runTest(TestSuite.java:208)
 at junit.framework.TestSuite.run(TestSuite.java:203)
 at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

 

   发表时间:2007-05-10  
把配置文件上传。。。。用代码看不清那里错了。(被砍的七七八八)
0 请登录后投票
   发表时间:2008-05-01  
小弟我不才,这几天也用aop搞事物。还算过了,看你的配置和我的配置,配置差不多,感觉你少写了一句话,打开对aop的支持。  o(∩_∩)o...。 我也是冇奏,你看看是不是。
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics