SpringBoot启动的时候报错: Error creating bean with name 'XXXX'

部署运行你感兴趣的模型镜像

Error creating bean with name 'XXXX'

完整报错如下:

 Exception encountered during context initialization - cancelling refresh attempt: 
 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 
 'testHelloController': Unsatisfied dependency expressed through field 'testHelloService'; nested exception is 
 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 
 'com.jun.service.test.TestHelloService' available: expected at least 1 bean which qualifies as autowire 
 candidate. Dependency annotations: 
 {@org.springframework.beans.factory.annotation.Autowired(required=true)}

原因分析:

因为是初学SpringBoot,只是想先让项目跑起来看看效果如果,费尽半天时间终于把项目结构搭建完整,一启动,就报这样的错,原因人家已经说得很清晰了,也就是在启动的时候找不到TestHelloService这个对象模板进行注入,又看了看service层已经打好注解@Service的,灵机一动,是不是SpringBoot启动的时候没有扫描得到Service层去,后面一看资料,果然如此,在SpringBoot的启动类Application中直接打一个注解@ComponentScan即可解决此问题:
如下:
报错前的代码:

package com.jun.web.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }
}

解决报错后的代码:

package com.jun.web.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

**@ComponentScan(basePackages = {"com.jun.core.*","com.jun.service.*","com.jun.web.*"})**
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }
}

您可能感兴趣的与本文相关的镜像

Llama Factory

Llama Factory

模型微调
LLama-Factory

LLaMA Factory 是一个简单易用且高效的大型语言模型(Large Language Model)训练与微调平台。通过 LLaMA Factory,可以在无需编写任何代码的前提下,在本地完成上百种预训练模型的微调

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值