2016-12-25 73 views
0
@Transactional 
@Repository 
@RepositoryDefinition(domainClass = UserApi.class, idClass = String.class) 
public interface UserApiRepository{ 

    @Cacheable(value="byUserId",key="#userId") 
    List<UserApi> findByUserId(String userId); 

    @CacheEvict(value="byUserId",key="#userApi.userId") 
    void save(UserApi userApi); 
} 

UsrApi.java春緩存 - 「空鍵返回緩存操作」

@Entity 
@Table(name = "user_api") 
public class UserApi { 
    private String id; 
    private String userId; 
    private String api; 
    private String platform; 
    private String apiType; 

    @Id 
    public String getId() { 
     return id; 
    } 

    public void setId(String id) { 
     this.id = id; 
    } 

    public String getUserId() { 
     return userId; 
    } 

    public void setUserId(String userId) { 
     this.userId = userId; 
    } 

    public String getApi() { 
     return api; 
    } 

    public void setApi(String api) { 
     this.api = api; 
    } 

    public String getPlatform() { 
     return platform; 
    } 

    public void setPlatform(String platform) { 
     this.platform = platform; 
    } 

    public String getApiType() { 
     return apiType; 
    } 

    public void setApiType(String apiType) { 
     this.apiType = apiType; 
    } 
} 

它的錯誤,當我添加key="#userId"

java.lang.IllegalArgumentException: Null key returned for cache operation 
(maybe you are using named params on classes without debug info?) 
Builder[public abstract java.util.List com.awinson.repository.UserApiRepository.findByUserId(java.lang.String)] 
caches=[byUserId] | key='#userId' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false' 

當我使用「save」方法時,它不更新緩存。

+0

你可以發佈'UserApi'類的代碼嗎? – developer

+0

我發佈了UserApi類的代碼 –

+0

那麼你是否有一個空用戶ID的用戶?你有'getId'和'getUserId'這個事實聽起來令人擔憂......這是用戶的標識符嗎? –

回答