【发布时间】:2017-07-02 03:25:06
【问题描述】:
我与上述异常叠加,并没有低估它出现的原因。我正在使用spring boot并通过注解声明bean。
应用程序由此类执行:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
我的问题 bean 有以下声明:
@Service
public class OrderSvc extends AbstractService implements DAOService {
我尝试将其放入以下 bean:
@RestController
public class OrderController {
@Autowired
CarSvc carSvc;
@Autowired
OrderSvc orderSvc;
出现异常:Could not autowire field: biz.Services.OrderSvc biz.controllers.rest.administrator.OrderController.orderSvc; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [biz.Services.OrderSvc] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
我还有 CarSvc bean,它与 OrderSvc 位于同一个包中,并扩展了相同的类,但注入没有问题
@Service
public class CarSvc extends AbstractService implements DAOService<Car> {
您知道为什么会出现此异常吗?
【问题讨论】:
-
在
OrderSvc中实现泛型接口DaoService<T>时没有声明类型。错字? -
是的,这是我的错,但这并不能解决我的问题。我仍然有注射的问题
-
OrderSvc是实现DAOService<Car>还是DAOService<any_other>? -
@RamanujaR
OrderSvc实现DAOService<Order>
标签: java spring spring-boot dependency-injection