SpringBoot编写自定义Starter
根据SpringBoot的Starter编写规则,需要编写xxxStarter依赖xxxAutoConfigurer,xxxStarter是一个空的jar,仅提供辅助性的依赖管理,引入其他类库
1.建立一个empty工程,建立一个普通maven模块xxxStarter,建立一个SpringBoot模块xxxAutoConfigurer,前者依赖后者
2.xxxAutoConfigurer:
新建:HelloService:
public class HelloService { private HelloProperties helloProperties; public void setHelloProperties(HelloProperties helloProperties) {
this.helloProperties = helloProperties;
}
public HelloProperties getHelloProperties() {
return helloProperties;
} public String hello(){
return StringFormatter.format("%s:你好,%s欢迎光临",helloProperties.getWeekend(),helloProperties.getName()).getValue();
}
}
新疆:HelloProperties类
@ConfigurationProperties(prefix = "brx")
public class HelloProperties { private String weekend; private String name; public String getWeekend() {
return weekend;
} public void setWeekend(String weekend) {
this.weekend = weekend;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}
新建:将启动类修改为一个配置类,并去除pom.xml中的maven插件
@Configuration
@EnableConfigurationProperties(HelloProperties.class)//只有在web上下文才起作用
@ConditionalOnWebApplication
public class BrxautoconfigApplication { @Autowired
HelloProperties helloProperties; @Bean
HelloService helloService(){
HelloService helloService = new HelloService();
helloService.setHelloProperties(helloProperties);
return helloService;
}
}
新建:META-INF/spring.factories:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.brx.demo.brxautoconfig.BrxautoconfigApplication
3.将starter和Autocofigure项目install到本地仓库
4.新建一个普通web项目,并添加xxxStarter库,并在application.properties添加:
brx.weekend="周一"
brx.name="白gg"
个人感觉:starter的意义就是把一些内部公用的代码抽成starter,共其他项目引入,并提供自动配置等功能
SpringBoot编写自定义Starter的更多相关文章
- SpringBoot编写自定义的starter 专题
What’s in a name All official starters follow a similar naming pattern; spring-boot-starter-*, where ...
- (springboot)自定义Starter
要引入的jar项目,即自定义的Starter项目: pom:(这里不能引入springboot整合否则测试项目注入失败) <?xml version="1.0" encodi ...
- SpringBoot编写自定义配置信息
⒈编写自定义配置类 1.浏览器配置 package cn.coreqi.security.properties; public class BrowserProperties { private St ...
- springboot 简单自定义starter - beetl
使用idea新建springboot项目beetl-spring-boot-starter 首先添加pom依赖 packaging要设置为jar不能设置为pom<packaging>jar ...
- springboot 简单自定义starter - dubbo
首先需要引入pom 这里使用nacos注册中心 所以引入了nacos-client 使用zookeeper注册中心的话需要引入其相应的client <dependency> <gro ...
- SpringBoot之旅第六篇-启动原理及自定义starter
一.引言 SpringBoot的一大优势就是Starter,由于SpringBoot有很多开箱即用的Starter依赖,使得我们开发变得简单,我们不需要过多的关注框架的配置. 在日常开发中,我们也会自 ...
- SpringBoot系列三:SpringBoot自定义Starter
在前面两章 SpringBoot入门 .SpringBoot自动配置原理 的学习后,我们对如何创建一个 SpringBoot 项目.SpringBoot 的运行原理以及自动配置等都有了一定的了解.如果 ...
- java框架之SpringBoot(10)-启动流程及自定义starter
启动流程 直接从 SpringBoot 程序入口的 run 方法看起: public static ConfigurableApplicationContext run(Object source, ...
- springboot核心技术(四)-----Docker、数据访问、自定义starter
Docker 1.简介 Docker是一个开源的应用容器引擎:是一个轻量级容器技术: Docker支持将软件编译成一个镜像:然后在镜像中各种软件做好配置,将镜像发布出去,其他使用者可以直接使 用这个镜 ...
随机推荐
- 转的,具体 https://www.cnblogs.com/icyJ/p/FreeShare.html
网络资源下载网址 屏幕录像.图像处理,汉化和破解版本很新.国内破解汉化:大眼仔旭 http://www.dayanzai.me/ 开发工具,系统,数据库 http://msdn.itellyou.cn ...
- 涂抹mysql笔记-mysql管理工具
五花八门的mysql管理工具<>mysql提供的命令行工具 mysql_install_db:mysql建库工具,在源码安装mysql环节我们使用过. mysql_safe:mysql启动 ...
- 团队第二次 # scrum meeting
github 本此会议项目由PM召开,召开时间为4-3日晚上9点 召开时长15分钟 任务表格 袁勤 学习SpringBoot https://github.com/buaa-2016/phyweb/i ...
- node.js打印function
var Person = function(name) { this.name = name; this.gender = ['man', 'woman']; } console.log(Person ...
- python-web自动化-Python+Selenium之expected_conditions:各种判断
expected_conditions一般也简称EC 以下两个条件类验证title,验证传入的参数title是否等于或包含于driver.titletitle_istitle_contains 以下两 ...
- 系统变量之System.getenv()和System.getProperty()
Java提供了System类的静态方法getenv()和getProperty()用于返回系统相关的变量与属性,getenv方法返回的变量大多于系统相关,getProperty方法返回的变量大多与ja ...
- Python:笔记1_字符串处理【转载】
[转载自:https://www.cnblogs.com/houht/p/3308634.html] 1. 判断字符串str是否为空Approach 1:如果字符串长度为0,说明字符串为空,code如 ...
- Xshell 6安装与使用教程
随着xshell5出现评估期已过的问题,发现好多人不知道怎么下载免费版的Xshell,在这里我将详细告诉大家如何下载和安装最新的Xshell6远程管理工具. Xshell安装 1.进入xshell英文 ...
- win10版office365激活序列码
win10版office365激活序列码(在别的地方找到一个) : NKGG6-WBPCC-HXWMY-6DQGJ-CPQVG 1.在线安装Office2016预览版后它是不会自动激活的,需在Offi ...
- 如何将 jar 包导入Maven 本地仓库
案例:oracle jar包由于在maven 远程仓库中找不到,需要先将oracle jar 文件下载到本地,然后导入maven本地仓库,就可以通过 pom 进行依赖 例如:下载后的 jar 地址 D ...