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支持将软件编译成一个镜像:然后在镜像中各种软件做好配置,将镜像发布出去,其他使用者可以直接使 用这个镜 ...
随机推荐
- 树莓派apt-get The value '\stable' is invalid for APT 错误
对apt-get进行任何操作都会报错: pi@raspberrypi:~ $ sudo apt-get upgrade Reading package lists... Done E: The val ...
- 创建一个HTTP接口测试
jmeter Apache JMeter是Apache组织开发的基于Java的压力测试工具. Apache jmeter 可以用于对静态的和动态的资源(文件,Servlet,Perl脚本,java 对 ...
- Mybatis调用数据库的存储过程和方法
转载. https://blog.csdn.net/ml0228123/article/details/81002258 上次的项目,要求我用java代码调用存储过程,折腾了好久.最后总算成功了 ...
- @method_decorator() 源码解析
# coding:utf-8 """ 作用: 原理:闭包 >> 1. 函数内部定义函数 2.内部函数使用外部函数的变量 3.外部函数返回内部函数的引用 带参数 ...
- java后台解析前端传来的json
@RequestMapping(value = {"save"}) @ResponseBody public Result save(TBaseInterventionPlan m ...
- vue.js+SSH添加和查询
Vue.js 是一套构建用户界面的渐进式框架.与其他重量级框架不同的是,Vue 采用自底向上增量开发的设计.Vue 的核心库只关注视图层,它不仅易于上手,还便于与第三方库或既有项目整合.另一方面,当与 ...
- Lua 和 C++ 交互
step1.搭建好vs和lua相交互的环境: 1.下载一个lua5.3的源码: 2.有Lua_lib.lib这个文件: 3.开始配置: 鼠标放在工程名那: 右键选属性: 把包含目录点开进行编辑: 地址 ...
- android 无法import
参考 https://blog.csdn.net/u012489412/article/details/72784095 File - Invalidate Caches/Restart
- 业务数据实体(model) 需要克隆的方法
业务数据实体(model) 需要克隆的时候 可以使用 Json.Deserialize<InquireResult>(Json.Serialize<InquireResult> ...
- 451. Sort Characters By Frequency将单词中的字母按照从高频到低频的顺序输出
[抄题]: Given a string, sort it in decreasing order based on the frequency of characters. Example 1: I ...