小编Kak*_*adu的帖子

在 Vaadin 和 Spring 中使用 @autowired 出现 NullPointerException

我正在 Vaadin 8 和 Spring 中从事简单的 bookLibrary 项目。我正在努力将服务类注入 UI 组件。它总是给我 nullPointerExceptionMessage 。我不会在任何地方使用“新”来创建服务。

这是 LibraryService 类:

 @Service
    public class LibraryService {
    @Autowired
    private BookDao bookDao;
    @Autowired
    private LibraryDao libraryDao;

    private static LibraryService libraryServiceInstance;

    private LibraryService() {

    }

    public static LibraryService getInstance() {
        if (libraryServiceInstance == null) {
            synchronized (LibraryService.class) {
                if (libraryServiceInstance == null) {
                    libraryServiceInstance = new LibraryService();
                }
            }
        }
        return libraryServiceInstance;
    }

    public void saveBook(Book book) {
        libraryDao.findAll().forEach(l -> l.getBooks().add(book));
        book.setLibrary(libraryDao.findOne(1L));
        bookDao.save(book);
    }

    public List<Book> getAllBooks() {
        List<Book> …
Run Code Online (Sandbox Code Playgroud)

java spring nullpointerexception autowired vaadin

4
推荐指数
1
解决办法
1640
查看次数

标签 统计

autowired ×1

java ×1

nullpointerexception ×1

spring ×1

vaadin ×1