5

This is my OffersDao class

package com.spring.dao;

import java.sql.*;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class OffersDao {


private NamedParameterJdbcTemplate jdbc;

    @Autowired
    public void setDataSource(DataSource jdbc) {
        this.jdbc=new NamedParameterJdbcTemplate(jdbc);
    }
}

When I am not autowiring the below part ,my app is working fine otherwise it is giving me above stated error

This is my spring context xml file

<?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"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">


    <context:annotation-config></context:annotation-config>
    <context:component-scan base-package="com.spring.dao"></context:component-scan>

    <jee:jndi-lookup jndi-name="jdbc/TestDB" id="dataSource"
        expected-type="javax.sql.DataSource">
    </jee:jndi-lookup>


</beans>

If anyone can tell me why this is happening. Moreover its a Maven Project.

Shubham Dixit
  • 9,242
  • 4
  • 27
  • 46

0 Answers0