Я пытаюсь создать компонент класса DatastoreRepository, но я получаю следующую ошибку Iam, используя spring-boot 2.1.3
Description:
The bean 'bookRepository', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
Это структура моего проекта. У меня есть основной класс выполнения Application в корне.такой пакет
com.mycompany.project
--Application.java
--controller
--domain
--repository
Класс с @SpringBootApplication
находится в корневом пакете
вот мой класс репозитория
import org.springframework.cloud.gcp.data.datastore.repository.DatastoreRepository;
public interface BookRepository extends DatastoreRepository<Book, Long>{
}
Вот мой класс домена
import org.springframework.cloud.gcp.data.datastore.core.mapping.Entity;
import org.springframework.data.annotation.Id;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Entity(name = "books")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Book {
@Id
Long id;
String title;
}
а вот мой класс контроллера
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class AppUserController {
@Autowired
BookRepository bookRepository;
@GetMapping("/booksave")
public String helloworld() {
bookRepository.save(new Book(3L, "author"));
return "book saved";
}
}
и вот мой класс приложения
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}