简体   繁体   English

springboot中如何使用@NoRepositoryBean注解

[英]How to use @NoRepositoryBean annotation in springboot

I tried to use @NoRepositoryBean annotations in springboot.我尝试在 springboot 中使用 @NoRepositoryBean 注释。 So I tried like this.所以我尝试这样。

import org.apache.ibatis.annotations.*;
import java.time.LocalDateTime;
import org.springframework.data.repository;

@NoRepositoryBean
public interface YearReportRepository {
   ...
   ...
}

But I got this error.但我收到了这个错误。 cannot find symbol @NoRepositoryBean

Please tell me how to use @NoRepositoryBean annotation.请告诉我如何使用@NoRepositoryBean 注释。

I'm looking at your code it I see that your repository does NOT extends any of the standard Spring repository interfaces, such as CrudRepository我看你的代码它,我看到你的资料库没有任何扩展标准的Spring库的接口,如CrudRepository

This means that there is no reason to put this annotation on it.这意味着没有理由把这个注解放在上面。 It will have no effect unless your repo interface extends one of the Spring repository interface.除非您的 repo 接口扩展了 Spring 存储库接口之一,否则它将无效。

Therefore, you can remove it.因此,您可以将其删除。 Here are more details about this annotation .以下是有关此注释的更多详细信息。

If this answer does not fully solve your problem, please, leave a comment below and I'll respond to it.如果这个答案不能完全解决您的问题,请在下面发表评论,我会回复。

cannot find symbol @NoRepositoryBean looks like you are not importing the @NoRepositoryBean in your code. cannot find symbol @NoRepositoryBean看起来您没有在代码中导入@NoRepositoryBean

  1. Check to see if your dependencies are good检查您的依赖项是否良好
  2. Check in your IDE if you can import it directly如果可以直接导入,请检查您的 IDE
  3. import org.springframework.data.repository.NoRepositoryBean;

Also your code should looks like this :此外,您的代码应如下所示:

import org.apache.ibatis.annotations.*;
import java.time.LocalDateTime;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.NoRepositoryBean;

@NoRepositoryBean
public interface YearReportRepository extends JpaRepository<Entity, Long> {
   ...
   ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM