簡體   English   中英

Spring JPA:PropertyReferenceException:找不到類型的屬性findAll

[英]Spring JPA: PropertyReferenceException: No property findAll found for type

我已經在這個問題上搜索了幾個小時,但找不到與我的情況完全匹配並且有解決方案的問題。

我有一個現有的 Cassandra 數據庫,但打算在不久的將來遷移到 MongoDB。 I'm writing a Spring Rest API with Spring Data JPA to use the Cassandra DB but want to make sure that I can easily switch to Mongo without much pain in the future.

@Entity
@Table("stb") 
public class NetworkDevice {
    @Id
    @PrimaryKeyColumn(name = "deviceid", type = PrimaryKeyType.PARTITIONED)
    private String deviceid;
// remaining fields/getters/setters/etc omitted

通用 NetworkDeviceRepository

public interface NetworkDeviceRepository {
    NetworkDevice findByDeviceid(String deviceid);
}

Cassandra 存儲庫

public interface NetworkDeviceCassandraRepository extends NetworkDeviceRepository, CassandraRepository<NetworkDevice, String>{}

Mongo 存儲庫

public interface NetworkDeviceMongoRepository extends NetworkDeviceRepository, MongoRepository<NetworkDevice, String> {}

當項目開始時,我最終出現以下錯誤

Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type NetworkDevice!

似乎 Spring 感到困惑並在我的NetworkDevice object 上尋找CrudRepository方法名稱作為字段,但這對我來說絕對沒有意義,而且我嘗試過的任何事情(幾個小時)都不會影響這個問題。

任何幫助將不勝感激,謝謝

我發現了這個問題。 顯然 Cassandra 將NetworkDeviceMongoRepository識別為潛在的 Cassandra 存儲庫,因為它與NetworkDeviceCassandraRepository位於相同的 package 中。

將這兩個存儲庫移動到不同的包解決了這個問題。


> Repository Package
    + NetworkDeviceRepository.java
    + NetworkDeviceMongoRepository.java
    + NetworkDeviceCassandraRepository.java


> Repository Package
    + NetworkDeviceRepository.java
    > Mongo Package
        + NetworkDeviceMongoRepository.java
    > Cassandra Package
        + NetworkDeviceCassandraRepository.java

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM