启用data-jpa dep时注入存储库的问题

时间:2019-10-20 19:00:03

标签: java spring spring-data-jpa spring-data spring-data-jdbc

当我取消注释JPA dep时,我注意到,如下所示:

implementation("org.springframework.boot:spring-boot-starter-jdbc")
implementation ("org.springframework.boot:spring-boot-starter-data-jdbc")
//implementation ("org.springframework.boot:spring-boot-starter-data-jpa")

启动时出现错误:

The bean 'myRepository', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.

实际上,我在启动时就收到了我所有存储库的错误,随机地它只是在第一次失败时就无法启动和停止。即我实际上没有在存储库中做一些重复的事情。

我使用的是id 'org.springframework.boot' version '2.2.0.RELEASE'

我完成了该项目的gradlew clean build,以确保没有剩余的食物。

我的存储库类是:

public interface MyRepository extends CrudRepository<MyModel, UUID> {

    @Query(rowMapperClass = MyModelRowMapper.class, value = "select my_uuid, my_code from my_model_table")
    Iterable<MyModel> findMyStuff();
}

MyModel在哪里

public class MyModel {

    @Id
    private UUID id;
    private String code; ...

只要我对spring-boot-starter-data-jpa进行评论,一切都可以。

想知道,如果有错误,或者我仍然missed to setup something

我得到了

@Configuration
@EnableJdbcRepositories
public class RepositoryConfig {
}

与所有存储库都位于同一软件包中。

毕竟,如果我不包含jpa,它就可以工作。我的代码中还没有任何JPA特定代码。

1 个答案:

答案 0 :(得分:1)

您需要确定不同的存储库仅由正确的Spring Data Module处理,方法是将它们和相应的Set xlObj = CreateObject("Excel.Application") Set objWorkbook = xlObj.Workbooks.Open("E:\Headers.xlsm") xlObj.Application.Visible = False xlObj.Workbooks.Add Dim result result = xlObj.Application.Run("Headers.xlsm!Headers",filename) xlFile.Close True xlObj.Quit 注释移动到单独的包中,或者通过为注释提供适当的过滤器。

否则,Spring Data将尝试创建错误类型的存储库,该存储库随后将失败,例如,因为找不到匹配的Function Headers(filename As String) As String Application.ScreenUpdating = False Dim myWb As Workbook Dim i As Integer Dim flag As Boolean Set myWb = Workbooks.Open(filename:=filename) Dim arr arr = Array("col1","col2") For i = 1 To 2 If Cells(1, i).Value = arr(i - 1) Then Headers = "True" Else Headers = "False , Not Found Header " & arr(i - 1) Exit Function End If Next myWb.Close End Function 注释。