我正在使用Spring开发一个应用程序.我需要使用@Service注释.我ServiceI和ServiceImpl这样ServiceImpl implements ServiceI.我在这里很困惑,我应该在哪里保留@Service注释.
我应该注释接口或实现@Service吗?这两种方法有什么不同?
我正在关注本教程(https://www.youtube.com/watch?v=Hu-cyytqfp8),并尝试在Spring Boot中连接到远程服务器上的MongoDB。运行应用程序时,我收到以下消息。
说明:com.mongotest.demo.Seeder中构造函数的参数0需要找不到“ com.mongotest.repositories.StudentRepository”类型的Bean。
行动:考虑在配置中定义一个类型为“ com.mongotest.repositories.StudentRepository”的bean。
项目结构。
这是我的课
@Document(collection = "Students")
public class Student {
@Id
private String number;
private String name;
@Indexed(direction = IndexDirection.ASCENDING)
private int classNo;
//Constructor and getters and setters.
}
================================
@Repository
public interface StudentRepository extends MongoRepository<Student, String>{
}
================================
@Component
@ComponentScan({"com.mongotest.repositories"})
public class Seeder implements CommandLineRunner{
private StudentRepository studentRepo;
public Seeder(StudentRepository studentRepo) {
super();
this.studentRepo = studentRepo;
}
@Override
public void run(String... args) throws Exception {
// TODO Auto-generated method stub
Student s1 …Run Code Online (Sandbox Code Playgroud)