-1

I have a repository interface as

@Repository
public interface WordRepository extends ReactiveCrudRepository<Word, Long> {}

And in the @SpringApplication class, I have

@Bean
ApplicationListener<applicationReadyEvent> ready(WordRepository rep) {
   ...
}

to populate some data to the database. It won't be compiled. After the message "APPLICATION FAILED TO START", it says

Action:

Consider defining a bean of type 'com.example.reactive.wordservice.WordRepository' in your configuration.

With or without the annotation @Repository won't yield a different outcome. I change to another approach with a new class instead.

@Component
class WordDataInitializer {

  private static Logger log = LoggerFactory.getLogger(WordDataInitializer.class);

  private WordRepository wordRepository;

  public WordDataInitializer(WordRepository wordRepository) {
    this.wordRepository = wordRepository;
  }

   @EventListener(ApplicationReadyEvent.class)
   public void initializeDB() throws URISyntaxException, IOException {
    ...
   }
}  

The outcome is still the same. I have done that many times and don't know why it doesn't work this time with Reactor. The Spring Boot is the latest version, 2.3.0 release.

What is missing?

vic
  • 2,548
  • 9
  • 44
  • 74
  • 1
    Looks like the component scan is configured incorectly. But for deeper analyzation we need atleast the package structure. – Jens May 26 '20 at 05:33
  • @Jens you are absolutely right. I will post detail in my own answer. – vic May 26 '20 at 17:40

1 Answers1

0

After waking up this morning, I recognized that a dependency I added might cause the problem. I added the Spring Boot starter data JPA to get the @Entity annotation. Removing the dependency solves the problem.

The Reactive DB works differently. The Entity is one case. Also, a schema.sql file won't get picked up automatically as the JPA approach does. I need to write some code to pick up the schema file.

vic
  • 2,548
  • 9
  • 44
  • 74