SpringBoot: Stereotype Annotations not working on Interface Level

597 Views Asked by At
   package com.Test.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan({"com.Test.springboot"})
public class SpringBoot1Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringBoot1Application.class, args);



    }

}

Controller Class

package com.Test.springboot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.Test.springboot.model.Student;
import com.Test.springboot.model.StudentDao;

@Controller
public class StudentController {
    @Autowired
    private StudentDao studentDao;

    @RequestMapping("/")
    public String homePage() {
        return "home";
    }

StudentDao

@Repository
public interface StudentDao {
    public Student addStudent(Student student);
    public Student getStudent(long id);
    public List<Student> getAllStudents();
    public String deleteStudent();

}

If we change the stereotype(Repository) annotation to implementation class it's working fine. but Interface level throwing an error(org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.vitechinc.springboot.model.StudentDao' available:)

1

There are 1 best solutions below

1
Pulsara Sandeepa On

Try adding below code as a maven dependancy in the pom.xml file:

I got the same issue and after installing this dependency now its working,

<dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.8</version>
        <scope>provided</scope>
</dependency>