我正在使用spring-boot來實現一些其他端點。我用@Autowired實現了AbstractRepository和AbstractEnpoint。然後兩者都被真正的2個端點擴展:ClientEndpoint和HospitalReservationListEndpoint。 但我得到在瀏覽器中出現以下錯誤,當我嘗試調用端點是neccessite庫方法:沒有合格的bean類型AbstractRepository <?>'可用:期望的單個匹配bean,但找到2
"org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.parcaune.reservationmanagerservices.core.AbstractRepository<?>' available: expected single matching bean but found 2: clientRepository,hospitalReservationListRepository"
我的課表:
我AbstractRepository
/*
@NoRepositoryBean
Annotation to exclude repository interfaces from being picked up
and thus in consequence getting an instance being created
*/
@NoRepositoryBean
public interface AbstractRepository<T> extends JpaRepository<T, String>
{
}
我AbstractEndpoint
public abstract class AbstractEndpoint<T> {
@Autowired
protected AbstractRepository<T> repository;
@GET
@Path("/ping")
@Produces(MediaType.TEXT_PLAIN)
public String ping() {
return "Endpoint works!";
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<T> getAll() {
List<T> list = new ArrayList<>();
list = repository.findAll();
return list;
}
}
我的客戶端類:
public interface ClientRepository extends AbstractRepository<Client> {
}
和
@Component
@Path("/clients")
public class ClientEndpoint extends AbstractEndpoint<Client> {
}
我的醫院 - 類
public interface HospitalReservationListRepository extends
AbstractRepository<HospitalReservationList> {
}
和
@Component
@Path("/hospitalreservationlist")
public class HospitalReservationListEndpoint extends
AbstractEndpoint<HospitalReservationList> {
}
更改代碼後出現同樣的錯誤 – Manu
我記得當我們嘗試使用Eclipse運行應用程序時遇到此錯誤的情況,但是當我們使用mvn spring-boot運行它時:運行我們沒有有任何問題。嘗試用mvn spring-boot運行它:運行也許它會幫助找到問題。 –
我再次得到相同的錯誤 – Manu