spring - Injecting bean declared in xml file using the @Inject annotation -


i can't @inject work properly. i'm trying inject bean xml using @inject annotation, error message "java.lang.illegalargumentexception: 'datasource' or 'jdbctemplate' required".

i have been trying in combination @qualifier("datasource"), wherever put @qualifier says "the annotation @qualifier disallowed location".

i have been reading loads of documentation on @inject , can't seem find mentions special treatment of beans declared in xml.

however, i'm guessing spring trying create foodaoimpl bean before scanning datasourcebean.

how go using @inject inject datasource bean declared in xml file? possible, using @inject?

foodaoimpl.java

@repository public class foodaoimpl extends namedparameterjdbcdaosupport implements foodao {  @inject private datasource datasource;  dslcontext create = dsl.using(datasource, sqldialect.db2);  } 

spring-module.xml

<?xml version="1.0" encoding="utf-8"?> <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-3.0.xsd">  <context:annotation-config />  <context:component-scan base-package="com.example.foobar" />  <bean id="datasource" class="com.mchange.v2.c3p0.combopooleddatasource"     destroy-method="close">      <property name="driverclass" value="com.ibm.db2.jcc.db2driver" />     <property name="jdbcurl" value="jdbc:db2://localhost:50000/blabla" />     <property name="user" value="papaya" />     <property name="password" value="coconut" /> </bean> 

cheers!

this works fine in spring. use @autowired annotation, not @inject.


Comments