我有三个类 Vehicle、Car 和 Truck。 Vehicle 类具有 Car 和 Truck 类的所有公共属性,并标记为 @NoMapppedBean
这里是课程的样子:
@MappedSuperclass
class Vehicle {
Long key;
String color;
String engineType;
String transmissionType;
}
@Entity
class Car {
Long id;
String carType;
}
@Entity
class Truck {
Long id;
boolean isMpv;
}
@NoRepositoryBean
public interface VehicleRepository<T extends Vehicle> extends JpaRepository<T, Long> {
//code to call the respective queries
}
public interface CarRepository extends VehicleRepository<Car> {}
public interface CarRepository extends VehicleRepository<Truck> {}
当我运行应用程序时,上面的代码在我的服务层上运行良好。现在我正在尝试用下面的代码为我的服务层编写测试用例。
@SpringBootTest
class TestCases {
@Autowired
private VehicleRepository<Car> carRepository;
}
这里当我自动装配
VehicleRepository<Car>
我收到以下错误:
com.jpa.demo.service.ProcessService required a bean of type 'com.jpa.demo.dao.VehicleRepository' that could not be found.
No qualifying bean of type 'com.jpa.demo.dao.VehicleRepository<com.jpa.demo.model.Car>' available: expected at least 1 bean which qualifies as autowire candidate.
我该如何解决这个错误?
解决此问题的任何帮助将不胜感激。谢谢!