Home > OS >  How to use @NoRepositoryBean annotation in springboot
How to use @NoRepositoryBean annotation in springboot

Time:11-06

I tried to use @NoRepositoryBean annotations in springboot. 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.

CodePudding user response:

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

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.

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.

CodePudding user response:

cannot find symbol @NoRepositoryBean looks like you are not importing the @NoRepositoryBean in your code.

  1. Check to see if your dependencies are good
  2. Check in your IDE if you can import it directly
  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> {
   ...
   ...
}
  • Related