Lombok生成器未生成生成器方法,推断的类型不符合上限

时间:2018-10-18 07:40:03

标签: java spring spring-boot lombok

我正在观看此视频教程,以稍微了解一下Spring:https://www.youtube.com/watch?v=-f-7l8X716k

我一直都很好,直到引入了@Builder注释。

尝试使用它时,我的构建失败并显示以下消息:

  

[错误]   ... spring / library / src / main / java / com / demo / LibraryApplication.java:[23,33]   方法保存在界面中   org.springframework.data.repository.CrudRepository不能是   适用于给定的类型;要求:找到S:   com.demo.domain.Book.BookBuilder原因:推断类型不   符合上限       推断:com.demo.domain.Book.BookBuilder       上限:com.demo.domain.Book

输出为BookBuilder,但在自动完成中却没有出现。

我发现了这个问题:inferred type does not conform to upper bound(s) hotelRepository.save(bookings) underlined

但是提供的解决方案没有任何改变。

这是怎么了?

编辑:我使用Eclipse STS

看着有效的POM,我看到了:

  • 龙目岛1.16.22
  • 与Spring相关的一切都是2.0.6.RELEASE

代码看起来像这样:

Book.java:

@Data
@NoArgsConstructor
@Builder
@AllArgsConstructor
@Entity
public class Book {

    @Id
    @GeneratedValue
    private long id;

    @NotNull
    private String title, isbn;
}

BookRepository.java:

@RepositoryRestResource(path = "books", collectionResourceRel = "books")
public interface BookRepository extends PagingAndSortingRepository<Book, Long> {

}

LibraryApplication.java:

@SpringBootApplication
public class LibraryApplication {

    @Autowired
    private BookRepository bookRepo;

    @Component
    class DataSetup implements ApplicationRunner {
        @Override
        public void run(ApplicationArguments args) throws Exception {
            bookRepo.save(Book.builder());
        }
    }

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

1 个答案:

答案 0 :(得分:3)

Book.builder返回一个CREATE MATERIALIZED VIEW DIM_DATE_MV BUILD IMMEDIATE REFRESH COMPLETE ON DEMAND START WITH sysdate NEXT (TRUNC(sysdate)+1) + 7 / 24 as SELECT CAL.DATE_D as ID_DATE, IS_WORKING_DAY as IS_WORKING_DAY, A.SUM as NB_WORKING_DAY_MONTH FROM (SELECT SUM(IS_WORKING_DAY) as SUM, OCAL.YEAR_MONTH_NUM as ID_MONTH from ODSISIC.ORACLE_CALENDAR OCAL group by OCAL.YEAR_MONTH_NUM) A INNER JOIN ODSISIC.ORACLE_CALENDAR CAL on CAL.YEAR_MONTH_NUM = A.ID_MONTH LEFT JOIN ODSISIC.DAY_OFF DOFF ON DOFF.DATE_OFF = CAL.DATE_D ; ,如果您要创建一本书,则可以在其中设置属性,只需执行以下操作即可:

BookBuilder

您可以查看lombok builder documentation