您的位置:程序门 -> java -> web 开发



spring使用配置事物管理,导致datasource初始化失败


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


spring使用配置事物管理,导致datasource初始化失败[无满意答案结贴,结贴人:broust]
发表于:2007-10-15 10:03:49 楼主
使用的是ww2+spring+hibernate3
applicationcontext.xml如下
<?xml   version="1.0"   encoding="utf-8"?>
<!doctype   beans   public   "-//spring//dtd   bean//en"   "http://www.springframework.org/dtd/spring-beans.dtd">
<beans   default-autowire="autodetect">
   
      <bean   id="datasource"   class="org.apache.commons.dbcp.basicdatasource"   destroy-method="close">
          <property   name="driverclassname">
              <value> com.mysql.jdbc.driver </value>
          </property>
          <property   name="url">
              <value> jdbc:mysql://localhost:3306/alibaba </value>
          </property>
          <property   name="username">
              <value> root </value>
          </property>
              <property   name="password">
              <value> </value>
          </property>
      </bean>

      <bean   id="sessionfactory"   class="org.springframework.orm.hibernate3.localsessionfactorybean">
          <property   name="datasource">
              <ref   bean="datasource"/>
          </property>
          <property   name="mappingresources">
              <list>
                  <value> com/ww2/common/pojo/catalog.hbm.xml </value>
              </list>
          </property>
          <property   name="hibernateproperties">
              <props>
                  <prop   key="hibernate.dialect">
                        org.hibernate.dialect.mysqldialect
                  </prop>
                  <prop   key="hibernate.show_sql">
                        true
                  </prop>
              </props>
          </property>
      </bean>

      <bean   id="transactionmanager"   class="org.springframework.orm.hibernate3.hibernatetransactionmanager">
          <property   name="sessionfactory">
              <ref   bean="sessionfactory"/>
          </property>
      </bean>
       
      <bean   id="homedao"   class="com.ww2.common.dao.homedaobject">
          <property   name="sessionfactory">
              <ref   bean="sessionfactory"/>
          </property>
      </bean>
      <!--    
      <bean   id="homedaoproxy"   class="org.springframework.transaction.interceptor.transactionproxyfactorybean">
            <property   name="transactionmanager">
              <ref   bean="transactionmanager"/>
          </property>
             
          <property   name="target">
              <ref   bean="homemanager"/>
          </property>
          <property   name="transactionattributes">
              <props>
                  <prop   key="insert*"> propagation_required </prop>
                  <prop   key="get*"> propagation_required,readonly </prop>
              </props>
          </property>
      </bean>
      -->
      <bean   id="homeaction"   class="com.ww2.common.action.homeaction"   singleton="false">
            <property   name="homemanager">
<ref   bean="homemanager"   />
    </property>
        </bean>
        <bean   id="homemanager"   class="com.ww2.common.management.homemanager"   singleton="true"   >
            <property   name="homedao">
<ref   bean="homedao"   />
    </property>
        </bean>
        <!--   add   your   spring   beans   here   -->
</beans>
//-----------------
web.xml如下
<?xml   version="1.0"   encoding="iso-8859-1"?>
<!doctype   web-app   public   "-//sun   microsystems,   inc.//dtd   web   application   2.3//en"   "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

        <display-name> acme   corp </display-name>

        <!--   start   snippet:   example   -->
        <filter>
                <filter-name> webwork </filter-name>
                <filter-class> com.opensymphony.webwork.dispatcher.filterdispatcher </filter-class>
        </filter>

        <filter-mapping>
                <filter-name> webwork </filter-name>
                <url-pattern> /* </url-pattern>
        </filter-mapping>

        <listener>
                <listener-class> org.springframework.web.context.contextloaderlistener </listener-class>
        </listener>
        <!--   end   snippet:   example   -->


        <welcome-file-list>
                <welcome-file> index.jsp </welcome-file>
                <welcome-file> default.jsp </welcome-file>
                <welcome-file> index.html </welcome-file>
        </welcome-file-list>

                <taglib-uri> webwork </taglib-uri>
                <taglib-location> /web-inf/lib/webwork-2.2.4.jar </taglib-location>
        <!--   end   snippet:   taglib   -->
        <resourcelink   name="jdbc/datasource"   global="jdbc/datasource"   type="javax.sql.datasourcer"/>
</web-app>
//--------------------
homedaobject.java如下
package   com.ww2.common.dao;

import   org.springframework.orm.hibernate3.support.hibernatedaosupport;

import   com.ww2.common.pojo.catalog;

public   class   homedaobject   extends   hibernatedaosupport   implements   homedao{

public   catalog   getcatalogbyid(integer   id){
return   (catalog)this.gethibernatetemplate().load(catalog.class,   id);
}
}
//--------------------------
出现的现象是,如果使用 <bean   id="homedaoproxy"   class="org.springframework.transaction.interceptor.transactionproxyfactorybean">
那么工程在启动的时候,就抛出cannot   create   jdbc   driver   of   class   ''   for   connect   url   'null'异常。
把这个事物代理注释掉,则正常。使用的是tomcat5.5

发表于:2007-10-15 11:37:401楼 得分:0
是配置文件的问题
把 <beans   default-autowire="autodetect"   >   改成
<beans   xmlns="http://www.springframework.org/schema/beans"   xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"   xsi:schemalocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
就可以。
晕死。。。


快速检索

最新资讯
热门点击