0
   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);



    }

}

控制器类

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";
    }

学生道

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

}

如果我们将构造型(存储库)注释更改为实现类,它就可以正常工作。但是接口级别抛出错误(org.springframework.beans.factory.NoSuchBeanDefinitionException:没有'com.vitechinc.springboot.model.StudentDao'类型的合格bean可用:)

4

1 回答 1

0

尝试在文件中添加以下代码作为 Maven 依赖项pom.xml

我遇到了同样的问题,在安装此依赖项后,它现在可以工作了,

<dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.8</version>
        <scope>provided</scope>
</dependency>
于 2021-01-28T17:21:08.013 回答