在测试自定义starter时,若出现无法找到helloservice的Bean的解决方法
2024-09-07 20:39:49
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; @Configuration
@ConditionalOnWebApplication//web应用才生效
@EnableConfigurationProperties(HelloProperties.class)
@ConditionalOnClass(HelloService.class)
public class HelloServiceAutoConfiguration {
@Autowired
HelloProperties helloProperties;
@Bean
public HelloService helloService(){
HelloService service = new HelloService();
service.setHelloProperties(helloProperties);
return service;
}
}
在方法helloService上加@Bean标签
最新文章
- eclipse SE增加Web开发插件
- Apache+PHP 配置随笔
- 【BZOJ-1692&;1640】队列变换 后缀数组 + 贪心
- hdu 1022 Train Problem I 解题报告
- codevs 1171 潜伏者
- 更改yum网易 阿里云的yum源。
- 每天一个Linux命令(08)--cp命令
- Java 9 尝鲜之JShell交互式编程环境
- CS:APP3e 深入理解计算机系统_3e Y86-64模拟器指南
- Dictionary排序
- select下拉框左右变换
- 【Java集合的详细研究4】Java中如何遍历Map对象的4种方法
- Debian 9 源配置
- js-学习笔记-Thunk函数
- LeetCode题解之 Implement strStr()
- 详解Linux(centos7)下安装OpenSSL安装图文方法
- ABP框架入门踩坑-使用MySQL
- oracle 网络配置 及 pl/sql 连接配置
- 小程序swiper 快速滑动闪屏
- 「COCI2016/2017 Contest #2」Bruza
热门文章
- 【Spring-Security】Re01 入门上手
- Flink-v1.12官方网站翻译-P003-Real Time Reporting with the Table API
- [WPF 学习] 18. 摄像头(肢解DirectShow)
- 2019 ICPC 上海区域赛总结
- 基于CentOS-7的redis下载和安装
- 梨子带你刷burp练兵场(burp Academy) - 服务端篇 - Sql注入配套漏洞讲解笔记
- OpenStack Train版-9.安装neutron网络服务(计算节点)
- msf 信息收集
- 事件循环 EventLoop(Promise,setTimeOut,async/await执行顺序)
- cheerio &; jQuery for server