根据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. 解决双击excel文件打开多个excel.exe进程的问题

    解决双击excel文件打开多个excel.exe进程的问题有些时候,双击两个excel文件,会打开多个excel进程,不同进程之间不能复制粘贴公式,只能粘贴数值,很不方便.怎么样双击多个excel文件 ...

  2. Android开发 :androidstudio device offline

    使用设备调试的时候,偶尔的就会遇到androidstudio device offline,尽管尝试开启/关闭  USB调试 .都无济于事. 如果PC安装了360手机助手就好办了(我的360手机助手 ...

  3. 廖雪峰Java7处理日期和时间-1概念-1日期和时间

    1.日期 日期是指某一天,如2016-11-20,2018-1-1 2.时间有2种: 不带日期的时间:14:23:54 带日期的时间:2017-1-1 20:21:23,唯一确定某个时刻 3.时区 时 ...

  4. Linux Bash Shell字符串分割substring等(转)

    原文https://blog.csdn.net/wuyinggui10000/article/details/52779364 脚本开发中遇到的问题是:原java中的字符串分割操作(substring ...

  5. Promise的实现原理

    1.Promise 介绍 Promise类似一个事务管理器,将用户异步操作流程用流水的形式来表达,用来延迟deferred和异步asynchronous. 特点如下: (1)对象的状态不受外界影响 P ...

  6. 网页提示504 gateway time-out是什么意思?如何解决?

    大家在访问网站的时候通常会遇到502错误.404错误等,很少会遇到504错误.但是在我们去访问大流量或者内容数据量较多的网站时,打开网页偶尔就会出现504 gateway time-out,这到底是什 ...

  7. 使用Go编写WebAssembly

    I. Install go 1. down https://golang.org/dl/ go1.12.3.windows-amd64.zip 2. set path (1) GOROOTvar na ...

  8. ORA-20011 问题处理

    今天巡检发现alert中报如下错: ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN ...

  9. Balls(扔鸡蛋问题)

    4554 BallsThe classic Two Glass Balls brain-teaser is often posed as:“Given two identical glass sphe ...

  10. openvas安装和基本使用

    OpenVAS是开放式漏洞评估系统,也可以说它是一个包含着相关工具的网络扫描器. OpenVAS是开放式漏洞评估系统,也可以说它是一个包含着相关工具的网络扫描器.其核心部件是一个服务器,包括一套网络漏 ...