根据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的更多相关文章

  1. SpringBoot编写自定义的starter 专题

    What’s in a name All official starters follow a similar naming pattern; spring-boot-starter-*, where ...

  2. (springboot)自定义Starter

    要引入的jar项目,即自定义的Starter项目: pom:(这里不能引入springboot整合否则测试项目注入失败) <?xml version="1.0" encodi ...

  3. SpringBoot编写自定义配置信息

    ⒈编写自定义配置类 1.浏览器配置 package cn.coreqi.security.properties; public class BrowserProperties { private St ...

  4. springboot 简单自定义starter - beetl

    使用idea新建springboot项目beetl-spring-boot-starter 首先添加pom依赖 packaging要设置为jar不能设置为pom<packaging>jar ...

  5. springboot 简单自定义starter - dubbo

    首先需要引入pom 这里使用nacos注册中心 所以引入了nacos-client 使用zookeeper注册中心的话需要引入其相应的client <dependency> <gro ...

  6. SpringBoot之旅第六篇-启动原理及自定义starter

    一.引言 SpringBoot的一大优势就是Starter,由于SpringBoot有很多开箱即用的Starter依赖,使得我们开发变得简单,我们不需要过多的关注框架的配置. 在日常开发中,我们也会自 ...

  7. SpringBoot系列三:SpringBoot自定义Starter

    在前面两章 SpringBoot入门 .SpringBoot自动配置原理 的学习后,我们对如何创建一个 SpringBoot 项目.SpringBoot 的运行原理以及自动配置等都有了一定的了解.如果 ...

  8. java框架之SpringBoot(10)-启动流程及自定义starter

    启动流程 直接从 SpringBoot 程序入口的 run 方法看起: public static ConfigurableApplicationContext run(Object source, ...

  9. springboot核心技术(四)-----Docker、数据访问、自定义starter

    Docker 1.简介 Docker是一个开源的应用容器引擎:是一个轻量级容器技术: Docker支持将软件编译成一个镜像:然后在镜像中各种软件做好配置,将镜像发布出去,其他使用者可以直接使 用这个镜 ...

随机推荐

  1. 【剑指offer】判断出栈序列是否合法

    输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应 ...

  2. 二叉树遍历(flist)(已知中序和按层遍历,求先序 )

    问题 F: 二叉树遍历(flist) 时间限制: 1 Sec  内存限制: 128 MB提交: 11  解决: 9[提交][状态][讨论版][命题人:quanxing][Edit] [TestData ...

  3. Emscripten 安装和使用

    OS: Windows 10 x64 I. install 0. pre install Python2.7 Node js Java 1. down git clone https://github ...

  4. mysql数据库优化(四)-项目实战

    在flask项目中,防止随着时间的流逝,数据库数据越来越多,导致接口访问数据库速度变慢.所以自己填充数据进行测试及 mysql优化 1.插入数据: 通过脚本,使用多进程,每100次提交数据 impor ...

  5. 深度学习原理与框架-Tfrecord数据集的读取与训练(代码) 1.tf.train.batch(获取batch图片) 2.tf.image.resize_image_with_crop_or_pad(图片压缩) 3.tf.train.per_image_stand..(图片标准化) 4.tf.train.string_input_producer(字符串入队列) 5.tf.TFRecord(读

    1.tf.train.batch(image, batch_size=batch_size, num_threads=1) # 获取一个batch的数据 参数说明:image表示输入图片,batch_ ...

  6. 搭建mxnet-gpu docker的pyhon remote kernel

    起因 最近看mxnet的东西,打算给实验室的机器装一个mxnet的环境,无奈实验室里面机器已经装了tensorflow,运行了好久了,环境比较老.而mxnet可是支持最新的cuda9.1和cudnn7 ...

  7. faster rcnn源码阅读笔记1

    自己保存的源码阅读笔记哈 faster rcnn 的主要识别过程(粗略) (开始填坑了): 一张3通道,1600*1600图像输入中,经过特征提取网络,得到100*100*512的feature ma ...

  8. es6之更优雅的条件语句

    在使用JavaScript时,条件判断是经常会用到的,一些简单的判断条件还可以接受,当遇到比较复杂多重条件时就比较恶心了.这里使用es6的小技巧使判断更优雅. 1.使用 Arrary.includes ...

  9. 动画优化、客户端存储、历史记录、worker

    一.requestAnimationFrame 1.requestAnimationFrame怎么用? 设置关键帧动画效果,注重关键帧执行的情况,用法与setTimeout一样 2.requestAn ...

  10. Python中*和**的作用(课堂小结)

    以前自学没注意过参数的传导中*和**的用法,这次趁着上课了解了一下,顺便写个随笔记一下. 1.打包用法 在参数传导中*args是不定长参数,传入的参数是不限制个数的,比如 def bdc(*args) ...