Injecting bean declared in xml file using the @Inject annotation

I can't get @Inject to work properly. I'm trying to inject a bean from xml using the @Inject annotation, but I get the error message "java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required".

I have also been trying in combination with @Qualifier("dataSource"), but wherever I put the @Qualifier it says "The annotation @Qualifier is disallowed for this location".

I have been reading loads of documentation on @Inject and I can't seem to find anything that mentions any special treatment of beans declared in xml.

However, I'm guessing Spring is trying to create the FooDaoImpl bean before scanning the dataSourceBean.

How would I go about using @Inject to inject the dataSource bean declared in the xml file? Is it even 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!

Answers


This works fine in Spring. I use the @Autowired annotation, not @Inject.


Need Your Help

Defining A Differential Equation Using matlabFunction

matlab function error-handling

I am trying solve the differential equation by first putting it in normal, which, if I did it correctly, should be dx/dt = a8 1/3 x - 1/3 b8, where a8 is the second derivative, and b8 is the third

Clear JPanel or JFrame

java swing graphics drawing

Without using super.paintComponent(g); can i still clear my Jpanel or Jframe Screen? I have some shapes drawn on JPanel and i want to clear all the drawing when user presses the right click without...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.