springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration. 报错Consider defining a bean of type

报错如图:

APPLICATION FAILED TO START 
Description : 
Parameter 2 of constructor in com.javasm.service.impl . sales. SalesOrderItemsServiceImp1 required a bean of type 
' com.javasm.domin . vo. sales . SalesGoodsVO ' 
that could not be found. 
Action : 
Consider defining a bean of type 
' com.javasm.domin . vo. sales . SalesGoodsVO ' 
in your configuration .

 

解决办法:

其实就是声明的变量没有被springboot注入容器 如图三个变量均进行了声明,均使用了@RequiredArgsConstructor+private final 但VO类其实没能注入容器

-@RequiredArgsConstructor//*0 
@Transactiona1 
- @Service 
public class SalesOrderItemsServiceImp1 extends BaseServiceimp1<Sa1esl 
private final SalesOrderItemsMapper salesOrderItemsMapper; 
private final SalesOrderItemsTransfer salesOrderItemsTransfer; 
private final SalesGoodsVO salesGoodsVO;

 

查看mapper接口,被springboot启动类上的注解以包扫描的形式注入了容器,所以没问题

3@SpringBootApp1ication 
@mapperScan(basePackages 
.com . mapper " 
@Enab1eTransactionmanagement// 
//@Enab1eSchedu1ing/,/ff,É'f-%%ißE 
public class ProjectApp1ication {

 

查看transfer类,被@Component注解声明,所以也没问题

- @Component 
- @RequiredArgsConstructor 
public class SalesOrderItemsTransfer extends Be

 

查看salesGoodsVO类,既没有包扫描,又没有@component注解,自然就报错了

解决办法 要么加上@component,要么自己new对象

private SalesGoodsVO salesGoodsVO 
new SalesGoodsVO();

posted @ 2021-10-05 00:05  夏·舍  阅读(2221)  评论(0编辑  收藏  举报