I have searched in every corner of the web with no result. I'm using Spring and trying to inject Jdbc operations into my DaoImpl class.
Seems like I am missing something as the DaoImpl class is returning null when querying for something, what am I doing wrong?
Bean configurations:
<bean id="transactionDao" class="jdbc.dao.OracleTransactionDao">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- ORACLE CONNECTION -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="${url}" />
<property name="username" value="${dbname}" />
<property name="password" value="${dbpassword}" />
</bean>
Interface dao:
interface TransactionDao extends Serializable {
public abstract void insert (Transaction transaction);
As you can see in the bean config, and in this class below, I'm currently both trying to inject the JdbcTemplate and trying to use the extended methods of JdbcDaoSupport Implementation dao:
OracleTransactionDao extends JdbcDaoSupport implements
TransactionDao {
@Autowired
JdbcTemplate template;
@Override
public void insert (Transaction transaction) {
List<Map<String, Object>> list;
try{
list = template
.queryForList("SELECT * FROM CUSTOMER");
}catch(NullPointerException e) {
list = this.queryForList("SELECT * FROM CUSTOMER");
}
System.out.println("called insert" + list.size());
}
My main: ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "beanConfigs.xml"); context.registerShutdownHook(); OracleTransactionDao dao = (OracleTransactionDao) context .getBean("transactionDao");
I must be missing some detail here?
Thanks in advance!
Unit test i mentioned in a comment. spring-context.xml:
TransactionDao:
TransactionDaoTest:
pom.xml (some deps are not needed):