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";
}StudentDao
@Repository
public interface StudentDao {
public Student addStudent(Student student);
public Student getStudent(long id);
public List<Student> getAllStudents();
public String deleteStudent();
}--如果我们将原型(Repository)注释更改为实现类,那么它就能正常工作。但是,接口级别抛出了一个error(org.springframework.beans.factory.NoSuchBeanDefinitionException: No合格bean,类型为“com.vitechinc.springboot.model.StudentDao”可用:)
发布于 2021-01-28 17:21:08
尝试将下面的代码作为maven依赖项添加到pom.xml文件中:
我也遇到了同样的问题,在安装了这个依赖程序之后,
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>https://stackoverflow.com/questions/60397220
复制相似问题