Could not autowire. No beans of ‘xxx‘ type found.

自定义starter的时候遇到的问题,网上看到有说没什么问题,idea debug级别调低就行,但试了不好使。

这里功能是希望能读取配置application.properties 的配置参数,并自动装配bean

package com.fengyu.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "hello")
public class HelloProperties {
    private String name;
    private String address;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "HelloProperties{" +
                "name='" + name + '\'' +
                ", address='" + address + '\'' +
                '}';
    }
}


但这里的AutoConfiguration就是取不到HelloProperties(已经在同一个文件夹下了)。

用其他项目调用这个starter,把装配这个bean 这段去掉是好使的,看来问题还是在 Could not autowire 这里

最后加这个注解就可以了:

@ComponentScan("com.fengyu")

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值