您的位置:程序门 -> java -> 框架、开源



搞了两天了 问下面的spring和hibernate整合的问题


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


搞了两天了 问下面的spring和hibernate整合的问题
发表于:2007-12-19 17:52:10 楼主
我的applicationcontext.xml如下:(我是在myeclipse里先添加的spring框架   然后再添加的hibernate框架)
<?xml   version="1.0"   encoding="utf-8"?>
<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">
      <bean   name="/adduser"  
class="com.test.struts.action.adduseraction">
<property   name="admindao">
<ref   bean="admindao"   />
</property>
</bean>
     

<bean   id="datasource"
class="org.apache.commons.dbcp.basicdatasource">
<property   name="driverclassname"
value="com.mysql.jdbc.driver">
</property>
<property   name="url"   value="jdbc:mysql://localhost:3306/test"> </property>
<property   name="username"   value="dreamteamustc"> </property>
<property   name="password"   value="dreamteamustc"> </property>
</bean>

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

<bean   id="admindao"   class="com.test.hibernate.admindao">
<property   name="sessionfactory">
<ref   bean="sessionfactory"   />
</property>
</bean> </beans>

我运行http://localhost:8081/test/form/userlogin.jsp点击submit按钮后   就会报如下的错误(baidu,google过了,没解决):
严重:   action:   null
org.springframework.beans.factory.beancreationexception:   error   creating   bean   with   name   '/adduser'   defined   in   servletcontext   resource   [/web-inf/classes/applicationcontext.xml]:   cannot   resolve   reference   to   bean   'admindao'   while   setting   bean   property   'admindao';   nested   exception   is   org.springframework.beans.factory.beancreationexception:   error   creating   bean   with   name   'admindao'   defined   in   servletcontext   resource   [/web-inf/classes/applicationcontext.xml]:   cannot   resolve   reference   to   bean   'sessionfactory'   while   setting   bean   property   'sessionfactory';   nested   exception   is   org.springframework.beans.factory.beancreationexception:   error   creating   bean   with   name   'sessionfactory'   defined   in   servletcontext   resource   [/web-inf/classes/applicationcontext.xml]:   invocation   of   init   method   failed;   nested   exception   is   java.lang.nosuchmethoderror:   org.objectweb.asm.classvisitor.visit(iiljava/lang/string;ljava/lang/string;[ljava/lang/string;ljava/lang/string;)v
caused   by:   org.springframework.beans.factory.beancreationexception:   error   creating   bean   with   name   'admindao'   defined   in   servletcontext   resource   [/web-inf/classes/applicationcontext.xml]:   cannot   resolve   reference   to   bean   'sessionfactory'   while   setting   bean   property   'sessionfactory';   nested   exception   is   org.springframework.beans.factory.beancreationexception:   error   creating   bean   with   name   'sessionfactory'   defined   in   servletcontext   resource   [/web-inf/classes/applicationcontext.xml]:   invocation   of   init   method   failed;   nested   exception   is   java.lang.nosuchmethoderror:   org.objectweb.asm.classvisitor.visit(iiljava/lang/string;ljava/lang/string;[ljava/lang/string;ljava/lang/string;)v
caused   by:   org.springframework.beans.factory.beancreationexception:   error   creating   bean   with   name   'sessionfactory'   defined   in   servletcontext   resource   [/web-inf/classes/applicationcontext.xml]:   invocation   of   init   method   failed;   nested   exception   is   java.lang.nosuchmethoderror:   org.objectweb.asm.classvisitor.visit(iiljava/lang/string;ljava/lang/string;[ljava/lang/string;ljava/lang/string;)v
caused   by:   java.lang.nosuchmethoderror:   org.objectweb.asm.classvisitor.visit(iiljava/lang/string;ljava/lang/string;[ljava/lang/string;ljava/lang/string;)v
at   net.sf.cglib.core.classemitter.begin_class(classemitter.java:77)
at   net.sf.cglib.core.keyfactory$generator.generateclass(keyfactory.java:173)
at   net.sf.cglib.core.defaultgeneratorstrategy.generate(defaultgeneratorstrategy.java:25)
at   net.sf.cglib.core.abstractclassgenerator.create(abstractclassgenerator.java:216)
at   net.sf.cglib.core.keyfactory$generator.create(keyfactory.java:145)
at   net.sf.cglib.core.keyfactory.create(keyfactory.java:117)
at   net.sf.cglib.core.keyfactory.create(keyfactory.java:108)
at   net.sf.cglib.core.keyfactory.create(keyfactory.java:104)
at   net.sf.cglib.proxy.enhancer. <clinit> (enhancer.java:69)
at   org.hibernate.proxy.pojo.cglib.cgliblazyinitializer.getproxyfactory


错误中有这段提示:java.lang.nosuchmethoderror:   org.objectweb.asm.classvisitor.visit
可是在我包括的lib库里   也是有的啊。。。   在asm-2.2.3.jar这个包里
发表于:2007-12-22 09:29:311楼 得分:0
应该是你的配置文件的问题  
要是方便的话+我qq1988696,我看看你代码,这么看实在找不出原因

这个问题我有个朋友也遇到过,他是在struts+spring+hibernate的时候遇到的,原因是一个jar包的冲突导致,不知道你这个是不是这个原因
发表于:2007-12-22 17:09:362楼 得分:0
个人怀疑是id="sessionfactory"   开头要小写,关联的bean都有set/get方法的时候   都很禁这个....楼主试试..
发表于:2007-12-24 09:34:433楼 得分:0
你的问题是
error       creating       bean       with       name       'sessionfactory'       defined       in       servletcontext      

发表于:2007-12-24 11:40:564楼 得分:0
缺少   cglib-full-2.0.2.jar  
发表于:2007-12-24 11:43:165楼 得分:0
你是不是又在搞网络书城,浪曦那个啊。都是jar包的祸
发表于:2007-12-24 17:32:396楼 得分:0
java.lang.nosuchmethoderror:   org.objectweb.asm.classvisitor.visit
缺少   asm.jar   这个包。
发表于:2007-12-25 11:08:457楼 得分:0
我把我的application.xml给你吧
<?xml   version="1.0"   encoding="utf-8"?>
<!doctype   beans   public   "-//spring//dtd   bean//en"   "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean   id="datasource"   class="org.apache.commons.dbcp.basicdatasource">
                <property   name="driverclassname">
                        <value> com.mysql.jdbc.driver </value>
                </property>
                <property   name="url">
                        <value> jdbc:mysql://localhost:3306/person </value>
                </property>
                <property   name="username">
                        <value> root </value>
                </property>
                <property   name="password">
                        <value> 12345678 </value>
                </property>
        </bean>

<!--     默认的就是localsessionfactorybean   -->
        <bean   id="sessoinfactory"   class="org.springframework.orm.hibernate3.localsessionfactorybean">
                <property   name="datasource">
                        <ref   bean="datasource"   />
                </property>
                <property   name="hibernateproperties">
                        <props>
                                <prop   key="hibernate.dialect"> org.hibernate.dialect.mysqldialect </prop>
                                <prop   key="connection.characterencoding"> utf8 </prop>
                                <prop   key="hibernate.show_sql"> true </prop>
                        </props>
                </property>
                <property   name="mappingdirectorylocations">
                        <list   >
                      <value> src/mapping </value>
                        </list>
                </property>
        </bean>

        <bean   id="hibernatetemplate"   class="org.springframework.orm.hibernate3.hibernatetemplate">
            <property   name="sessionfactory">
              <ref   bean="sessoinfactory"/>
            </property>
            <property   name="allowcreate">
                <value> true </value>
            </property>
        </bean>

        <bean   id="testdao"   class="mapping.testdao">
            <property   name="hibernatetemplate">
                <ref   bean="hibernatetemplate"/>
            </property>
        </bean>
</beans>


快速检索

最新资讯
热门点击