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可用:)