This has been happening ever since i moved from Spring Data MongoDB to Spring Data Couchbase but even deleting the project as a whole and recreating did not solve the problem.
Every time I start my application throws:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.minerva.borrowings.services.BorrowingServiceImpl required a bean of type 'com.minerva.borrowings.repositories.BorrowingRepo' that could not be found.
Action:
Consider defining a bean of type 'com.minerva.borrowings.repositories.BorrowingRepo' in your configuration.
Process finished with exit code 0
But my file structure is:
└───com
└───minerva
└───borrowings
│ BorrowingsApplication.java
│
├───config
│ LoggingConfig.java
│ NotificationConfig.java
│
├───controllers
│ BorrowingController.java
│
├───entities
│ Borrowing.java
│
├───exceptions
│ BorrowingNotFoundException.java
│ BorrowingServerErrorException.java
│ NullBodyException.java
│ NullIdException.java
│ UnknownIdTypeException.java
│
├───repositories
│ BorrowingRepo.java
│
└───services
BorrowingNotificationSender.java
BorrowingService.java
BorrowingServiceImpl.java
And the repository file is as such:
package com.minerva.borrowings.repositories;
import com.minerva.borrowings.entities.Borrowing;
import org.springframework.data.couchbase.repository.CouchbaseRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface BorrowingRepo extends CouchbaseRepository<Borrowing, String> {
}
And my BorrowingApplication.java uses @SpringBootApplication
and does not allow to use @ComponentScan
or @EnableJpaRepository
My pom.xml file is as such:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.minerva</groupId>
<artifactId>borrowings</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>borrowings</name>
<description>borrowings</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-couchbase</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.13</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
I've tried using JpaRepository and CrudRepository but the problem remains
CodePudding user response:
Try out the @EnableCouchbaseRepositories
annotation, maybe even by specifying the basePackages
. Add a configuration bean like this:
@Configuration
@EnableCouchbaseRepositories(basePackages = "com.minerva.borrowings.repositories")
class CouchbaseDbConfig {
}