java - BeanCreationException: Injection of autowired dependencies failed -


i want use spring jdbc configuration.

but throws next bunch of exceptions:

exception in thread "main" org.springframework.beans.factory.beancreationexception: error creating bean name 'jdbcdaoimpl': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: public javax.sql.datasource com.spring.database.dao.jdbcdaoimpl.datasource; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'datasource' defined in class path resource [spring-db.xml]: error setting property values; nested exception org.springframework.beans.propertybatchupdateexception; nested propertyaccessexceptions (1) are: propertyaccessexception 1: org.springframework.beans.methodinvocationexception: property 'driverclassname' threw exception; nested exception java.lang.nosuchmethoderror: org.springframework.util.classutils.forname(ljava/lang/string;)ljava/lang/class;     @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:292)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1185)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:537)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:475)     @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:304)     @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:228)     @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:300)     @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:195)     @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:703)     @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:760)     @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:482)     @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:139)     @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:83)     @ com.spring.database.jdbcdemo.main(jdbcdemo.java:10)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:483)     @ com.intellij.rt.execution.application.appmain.main(appmain.java:134) caused by: org.springframework.beans.factory.beancreationexception: not autowire field: public javax.sql.datasource com.spring.database.dao.jdbcdaoimpl.datasource; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'datasource' defined in class path resource [spring-db.xml]: error setting property values; nested exception org.springframework.beans.propertybatchupdateexception; nested propertyaccessexceptions (1) are: propertyaccessexception 1: org.springframework.beans.methodinvocationexception: property 'driverclassname' threw exception; nested exception java.lang.nosuchmethoderror: org.springframework.util.classutils.forname(ljava/lang/string;)ljava/lang/class;     @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:508)     @ org.springframework.beans.factory.annotation.injectionmetadata.inject(injectionmetadata.java:87)     @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:289)     ... 18 more caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'datasource' defined in class path resource [spring-db.xml]: error setting property values; nested exception org.springframework.beans.propertybatchupdateexception; nested propertyaccessexceptions (1) are: propertyaccessexception 1: org.springframework.beans.methodinvocationexception: property 'driverclassname' threw exception; nested exception java.lang.nosuchmethoderror: org.springframework.util.classutils.forname(ljava/lang/string;)ljava/lang/class; 

here main():

public class jdbcdemo {     public static void main(string[] args) {         applicationcontext context = new classpathxmlapplicationcontext("spring-db.xml");         jdbcdaoimpl dao = context.getbean("jdbcdaoimpl", jdbcdaoimpl.class);          circle circle = dao.getcircle(1);         system.out.println(circle.getname());     } } 

jdbcdaoimpl:

@component public class jdbcdaoimpl {     public static final string select_from_circle_where_id = "select * circle id = ?";      private logger log = logger.getlogger(jdbcdaoimpl.class);     @autowired     private datasource datasource;      public circle getcircle(int circleid) {         connection conn = null;         preparedstatement ps;         resultset rs;         circle circle = null;         try {             conn = datasource.getconnection();             ps = conn.preparestatement(select_from_circle_where_id);             ps.setint(1, circleid);              rs = ps.executequery();             if (rs.next()) {                 circle = new circle(circleid, rs.getstring("name"));             }              rs.close();             ps.close();         } catch (exception e) {             log.error(e);             throw new runtimeexception(e);         } {             try {                 if (conn != null) {                     conn.close();                 }             } catch (sqlexception e) {                 log.error(e);             }         }         return circle;     } } 

spring-db.xml:

<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"        xsi:schemalocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd     http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context.xsd">      <context:annotation-config/>     <context:component-scan base-package="com.spring.database"/>      <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource" >         <property name="driverclassname" value="org.apache.derby.jdbc.clientdriver"/>         <property name="url" value="jdbc:derby://localhost:1527/db;create=true" />     </bean>     </beans> 

how solve trouble?

looks class path problem. method complains removed in spring 4;

you should double-check versions of spring dependencies have same version.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -