为什么我的 springboot 应用程序看不到 @Service 注释?

why my springboot app cant see @Service annotation?

我的服务class

package poklakni.library.service;
import java.util.List;
import java.util.function.Predicate;
import org.springframework.stereotype.Service;
import poklakni.library.entity.Book;

@Service
public interface BookService {

    //some crud methods
}

主要class

package poklakni.library;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import poklakni.library.repository.BookRepository;
import poklakni.library.repository.PersonRepository;
import poklakni.library.service.BookService;
import poklakni.library.service.PersonService;

@SpringBootApplication
public class Application implements CommandLineRunner {

    @Autowired
    private BookService bookService;

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

    @Override
    public void run(String... args) throws Exception {

        //more code
    }
}

上面写着

***************************
APPLICATION FAILED TO START
***************************
Description:

Field bookService in poklakni.library.Application required a bean of type 
'poklakni.library.service.BookService' that could not be found.

Action:

Consider defining a bean of type 'poklakni.library.service.BookService' in 
your configuration.

即使我添加 @ComponentScan ("poklakni.library") 它也不起作用

我也有带有@Repository 注释的回购协议,它完美地自动写入 但服务不工作 我究竟做错了什么? 谢谢你的建议

编辑:还有一个服务实现 包裹 poklakni.library.service;

import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;

import poklakni.library.entity.Book;
import poklakni.library.repository.BookRepository;
import poklakni.library.repository.PersonRepository;

public class BookServiceImpl implements BookService {

    @Autowired
    private BookRepository bookRepo;

    //more code
}

BookService是接口,不能实例化。 @Service 应该放在实现 BookService.

的具体 class 上

请将您的 BookServiceImpl 注释为 @Service

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookRepository bookRepo;

    //more code
}