spring - NoSuchMethodException from LocalSessionFactoryBuilder -
im curently working on project using spring (3.1.0) , hibernate (4.2.0.final) , error when loading app. think maven problem can't see wich one. saw on different topics problems similar null pointer exception wich not case.
here pom.xml
<properties> <spring.version>3.1.0.release</spring.version> <hibernate.version>4.2.0.final</hibernate.version> </properties> <dependencies> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupid>org.aspectj</groupid> <artifactid>aspectjrt</artifactid> <version>1.6.12</version> </dependency> <dependency> <groupid>org.aspectj</groupid> <artifactid>aspectjweaver</artifactid> <version>1.6.12</version> </dependency> <dependency> <groupid>commons-lang</groupid> <artifactid>commons-lang</artifactid> <version>2.6</version> </dependency> <dependency> <groupid>servletapi</groupid> <artifactid>servletapi</artifactid> <version>2.4</version> <scope>provided</scope> </dependency> <dependency> <groupid>jstl</groupid> <artifactid>jstl</artifactid> <version>1.2</version> </dependency> <dependency> <groupid>commons-logging</groupid> <artifactid>commons-logging</artifactid> <version>1.1.1</version> </dependency> <dependency> <groupid>org.codehaus.jackson</groupid> <artifactid>jackson-mapper-asl</artifactid> <version>1.9.3</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-aop</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-orm</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-core</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-config</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-web</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-taglibs</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>commons-dbcp</groupid> <artifactid>commons-dbcp</artifactid> <version>1.4</version> </dependency> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-api</artifactid> <version>1.6.4</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> <version>${hibernate.version}</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-annotations</artifactid> <version>3.5.6-final</version> </dependency> <dependency> <groupid>org.hsqldb</groupid> <artifactid>hsqldb</artifactid> <version>2.2.6</version> </dependency> </dependencies>
and persistence context configuration:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd "> <bean class="org.springframework.beans.factory.config.propertyplaceholderconfigurer"> <property name="location" value="classpath:/jdbc.properties"/> </bean> <bean id="datasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <property name="driverclassname" value="org.hsqldb.jdbcdriver" /> <property name="url" value="${jdbc.connectionurl}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> <bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybuilder"> <property name="datasource" ref="datasource" /> <property name="packagestoscan" value = "test.entity"/> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.hsqldialect </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">create</prop> </props> </property> </bean> <bean id="transactionmanager" class="org.springframework.orm.hibernate3.hibernatetransactionmanager"> <property name="sessionfactory" ref="sessionfactory" /> </bean> <aop:config> <aop:pointcut id="webmethods" expression="execution(* ro.alten.altenrointranet.service.*.*(..))" /> <aop:advisor advice-ref="txadvice" pointcut-ref="webmethods" /> </aop:config> <tx:advice id="txadvice" transaction-manager="transactionmanager"> <tx:attributes> <tx:method name="*" propagation="required" /> </tx:attributes> </tx:advice>
for call of session factoru did daoutil that:
public class daoutils { @autowired protected localsessionfactorybuilder localsessionfactorybuilder; protected sessionfactory getsessionfactory() { return localsessionfactorybuilder.buildsessionfactory(); } }
and call that:
@component public class daopersonne extends daoutils{ public void save(person p) { this.getsessionfactory().getcurrentsession().save(p); } public list<person> getpersonneall() { return this.getsessionfactory().getcurrentsession(). createquery("from person").list(); } }
the error message is:
org.springframework.beans.factory.beancreationexception: error creating bean name 'personcontroller': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: private ro.alten.altenrointranet.service.servicetest ro.alten.altenrointranet.controller.personcontroller.servicetest; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'servicetest': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: private ro.alten.altenrointranet.dao.daopersonne ro.alten.altenrointranet.service.servicetest.daopersonne; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'daopersonne': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: protected org.springframework.orm.hibernate4.localsessionfactorybuilder ro.alten.altenrointranet.dao.daoutils.localsessionfactorybuilder; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'sessionfactory' defined in servletcontext resource [/web-inf/persistence-context.xml]: instantiation of bean failed; nested exception org.springframework.beans.beaninstantiationexception: not instantiate bean class [org.springframework.orm.hibernate4.localsessionfactorybuilder]: no default constructor found; nested exception java.lang.nosuchmethodexception: org.springframework.orm.hibernate4.localsessionfactorybuilder.<init>() @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:287) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1106) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:517) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:294) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:225) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:291) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:585) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:913) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:464) @ org.springframework.web.servlet.frameworkservlet.configureandrefreshwebapplicationcontext(frameworkservlet.java:631) @ org.springframework.web.servlet.frameworkservlet.createwebapplicationcontext(frameworkservlet.java:588) @ org.springframework.web.servlet.frameworkservlet.createwebapplicationcontext(frameworkservlet.java:645) @ org.springframework.web.servlet.frameworkservlet.initwebapplicationcontext(frameworkservlet.java:508) @ org.springframework.web.servlet.frameworkservlet.initservletbean(frameworkservlet.java:449) @ org.springframework.web.servlet.httpservletbean.init(httpservletbean.java:133) @ javax.servlet.genericservlet.init(genericservlet.java:244) @ org.apache.catalina.core.standardwrapper.initservlet(standardwrapper.java:1453) @ org.apache.catalina.core.standardwrapper.load(standardwrapper.java:1250) @ org.apache.catalina.core.standardcontext.loadonstartup(standardcontext.java:5093) @ org.apache.catalina.core.standardcontext.start(standardcontext.java:5380) @ com.sun.enterprise.web.webmodule.start(webmodule.java:498) @ org.apache.catalina.core.containerbase.addchildinternal(containerbase.java:917) @ org.apache.catalina.core.containerbase.addchild(containerbase.java:901) @ org.apache.catalina.core.standardhost.addchild(standardhost.java:733) @ com.sun.enterprise.web.webcontainer.loadwebmodule(webcontainer.java:2019) @ com.sun.enterprise.web.webcontainer.loadwebmodule(webcontainer.java:1669) @ com.sun.enterprise.web.webapplication.start(webapplication.java:109) @ org.glassfish.internal.data.engineref.start(engineref.java:130) @ org.glassfish.internal.data.moduleinfo.start(moduleinfo.java:269) @ org.glassfish.internal.data.applicationinfo.start(applicationinfo.java:301) @ com.sun.enterprise.v3.server.applicationlifecycle.deploy(applicationlifecycle.java:461) @ com.sun.enterprise.v3.server.applicationlifecycle.deploy(applicationlifecycle.java:240) @ org.glassfish.deployment.admin.deploycommand.execute(deploycommand.java:389) @ com.sun.enterprise.v3.admin.commandrunnerimpl$1.execute(commandrunnerimpl.java:348) @ com.sun.enterprise.v3.admin.commandrunnerimpl.docommand(commandrunnerimpl.java:363) @ com.sun.enterprise.v3.admin.commandrunnerimpl.docommand(commandrunnerimpl.java:1085) @ com.sun.enterprise.v3.admin.commandrunnerimpl.access$1200(commandrunnerimpl.java:95) @ com.sun.enterprise.v3.admin.commandrunnerimpl$executioncontext.execute(commandrunnerimpl.java:1291) @ com.sun.enterprise.v3.admin.commandrunnerimpl$executioncontext.execute(commandrunnerimpl.java:1259) @ com.sun.enterprise.v3.admin.adminadapter.docommand(adminadapter.java:461) @ com.sun.enterprise.v3.admin.adminadapter.service(adminadapter.java:212) @ com.sun.grizzly.tcp.http11.grizzlyadapter.service(grizzlyadapter.java:179) @ com.sun.enterprise.v3.server.hk2dispatcher.dispath(hk2dispatcher.java:117) @ com.sun.enterprise.v3.services.impl.containermapper$hk2dispatchercallable.call(containermapper.java:354) @ com.sun.enterprise.v3.services.impl.containermapper.service(containermapper.java:195) @ com.sun.grizzly.http.processortask.invokeadapter(processortask.java:860) @ com.sun.grizzly.http.processortask.doprocess(processortask.java:757) @ com.sun.grizzly.http.processortask.process(processortask.java:1056) @ com.sun.grizzly.http.defaultprotocolfilter.execute(defaultprotocolfilter.java:229) @ com.sun.grizzly.defaultprotocolchain.executeprotocolfilter(defaultprotocolchain.java:137) @ com.sun.grizzly.defaultprotocolchain.execute(defaultprotocolchain.java:104) @ com.sun.grizzly.defaultprotocolchain.execute(defaultprotocolchain.java:90) @ com.sun.grizzly.http.httpprotocolchain.execute(httpprotocolchain.java:79) @ com.sun.grizzly.protocolchaincontexttask.docall(protocolchaincontexttask.java:54) @ com.sun.grizzly.selectionkeycontexttask.call(selectionkeycontexttask.java:59) @ com.sun.grizzly.contexttask.run(contexttask.java:71) @ com.sun.grizzly.util.abstractthreadpool$worker.dowork(abstractthreadpool.java:532) @ com.sun.grizzly.util.abstractthreadpool$worker.run(abstractthreadpool.java:513) @ java.lang.thread.run(thread.java:722)
after see on net, looks maven problem try different methode in way no results.
- clean , build
- delete .m2 directory , redownload dependencies
- run mvn dependency:tree
but problem still there , starting annoy me. can give me hints discover problem come ?
i know can solve problem using older version of hibernate , spring know better practice hibernate 4.0.
thank you
the hibernate version used 4. therefore, need change spring hibernate package 3 4, i.e:
- change
org.springframework.orm.hibernate3.hibernatetransactionmanager
org.springframework.orm.hibernate4.hibernatetransactionmanager
edit 1:
change org.springframework.orm.hibernate4.localsessionfactorybuilder
org.springframework.orm.hibernate4.localsessionfactorybean
Comments
Post a Comment