I am building a Spring-boot application where I am using Spring data jpa feature.
Please find below my dao layer code
package com.adv.dao;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface CustomerDao extends JpaRepository<Customer, String> {
}
I am using a DaoProvider class as follows:
package com.adv.dao;
import java.io.Serializable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@Repository
public class DaoProvider implements Serializable {
private static final long serialVersionUID = 1L;
@Autowired
private CustomerDao customerDao;
public CustomerDao getCustomerDao() {
return customerDao;
}
}
My spring boot main class is defined as follows:
@SpringBootApplication
@ComponentScan(basePackages="com.adv")
public class AdvMain extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(AdvMain.class);
}
public static void main(String[] args) {
SpringApplication.run(AdvMain.class, args);
}
}
Now during runtime I am getting following exception:
Field customerDao in com.adv.dao.DaoProvider required a bean of type 'com.adv.dao.CustomerDao' that could not be found.
I guess that @Repository
annotation on interface CustomerDao
is not working.
But I am unable to figure out the issue.Can anyone figure out the problem?