说明

命名规约

官方命名:

  • spring-boot-starter-xxx

自定义命名:

  • xxx-spring-boot-starter

步骤

1、在idea中新建一个普通Maven模块:Jing-spring-boot-starter

2、新建一个Springboot模块:JIng-spring-boot-starter-aoutoconfigure

3、在starter中导入autoconfigure的依赖

<dependency><groupId>com.lili</groupId><artifactId>jing-springboot-starter-autoconfig</artifactId><version>0.0.1-SNAPSHOT</version>
</dependency>

4、编写一个类用来测试

@ConfigurationProperties(prefix = "com.lili")
public class HelloProperties {private String name;private int age;public void setName(String name){this.name = name;}public String getName(){return this.name;}public void setAge(int age){this.age = age;}public int getAge(){return this.age;}@Overridepublic String toString() {return "HelloProperties{" +"name='" + name + '\'' +", age=" + age +'}';}
}
public class HelloService {private HelloProperties helloProperties;public void setHelloProperties(HelloProperties helloProperties) {this.helloProperties = helloProperties;}public HelloProperties getHelloProperties() {return helloProperties;}public void show(){System.out.println("你好,丽丽");}
}

5、编写一个配置类并注入bean进行测试

@Configuration
@ConditionalOnWebApplication
@EnableConfigurationProperties(HelloProperties.class)
public class HelloServiceAutoConfiguration {@AutowiredHelloProperties helloProperties;@Beanpublic HelloService helloService(){HelloService helloService = new HelloService();helloService.setHelloProperties(helloProperties);return helloService;}
}

6、在resources编写一个自己的META-INF\spring.factories,内容如下

org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.lili.config.HelloServiceAutoConfiguration

7、新建一个Maven模块进行测试,需要导入自定义的启动器

        <!--导入自定义的测试器进行测试--><dependency><groupId>com.lili</groupId><artifactId>jing-springboot-starter</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>

8、编写Controller

@RestController
public class HelloController {@AutowiredHelloService helloService;@RequestMapping("/helloStart")public HelloService getMessage(){return helloService;}
}

9、在properties里面可以给属性赋值

com.lili.name=张三
com.lili.age=23

10、运行然后访问

到这里,我们自己定义的starter就成功啦!

springboot自定义starter启动器相关推荐

  1. @configurationproperties注解的使用_徒手使用SpringBoot自定义Starter启动器

    前言 在使用SpringBoot框架时,SpringBoot 最强大的功能就是把我们常用的场景抽取封装成了一个个starter,将其称之为场景启动器.搭建项目时,通过引入SpringBoot为我提供的 ...

  2. 进阶篇-SpringBoot2.x自定义starter启动器

    1.本篇前言 Spring Boot为我们提供了简化企业级开发绝大多数场景的 starter pom[比如springb-boot-starter-web,springb-boot-starter-j ...

  3. SpringBoot自定义start启动器图文教程(详细)

    这里写目录标题 1.SpringBoot启动器原理 2.自定义starter 到这已经完成启动stater启动的配置了 1.SpringBoot启动器原理 我们新建一个空的spring boot项目, ...

  4. SpringBoot自定义Starter(自动配置类)

    前言 SpringBoot其实从诞生以来围绕的核心就是快速构建项目,快速构建的前提是有人帮你做好轮子,开发者只要拿来即用就好了,而造好轮子的人就是SpringBoot的开发者,引入自动配置的形式帮助开 ...

  5. SpringBoot 自定义Starter(阿里云短信、消息推送)

    首先在IDEA中创建SpringBoot项目,引入相关必要依赖,本次以阿里云短信/消息推送为例: <dependency><groupId>com.aliyun</gro ...

  6. SpringBoot 自定义starter 保姆级教程(说明+源码+配置+测试)

    1.说明 命名归约-官方命名: 前缀:spring-boot-starter-xxx(比如:spring-boot-starter-web) 命名归约-自定义命名: xxx-spring-boot-s ...

  7. SpringBoot自定义starter时报错:Problems:dependencies.dependency.version‘ for com.zsm.starter:zsm-spring

    Problems:dependencies.dependency.version' for com.zsm.starter:zsm-spring-boot-starter-autoconfigurej ...

  8. SpringBoot 自定义实现一个启动器starter 教程。

    说明:springboot 官方给我们提供了很多启动器如:elasticsearch,aop,redis...等等 但是实际开发中,可能不同公司的业务不同需要定制化一个通用的专属的启动器来满足公司内部 ...

  9. springboot框架学习 - 自定义 starter

    本篇主要演示 springboot 中自定义 starter 的实例,不涉及底层原理. 首先,创建一个什么都没有的工程作为父工程,这个工程不需要进行任何操作,然后创建两个模块,分别命名为 tyu-he ...

  10. 玩转 SpringBoot 2.x 之自定义Starter依赖

    前言 SpringBoot 核心功能之一就是 starter 依赖也叫起步依赖,他默认提供了 spring-boot-starter-web.spring-boot-starter-logging.s ...

最新文章

  1. volatile关键字的作用、原理
  2. AI高分通过美国8年级科学考试:常识题推理题都能行,不服可同台对战
  3. 吹爆google colab
  4. XVI Open Cup named after E.V. Pankratiev. GP of Eurasia
  5. Flask知识点回顾以及重点内容
  6. NG Command(命令)
  7. MATLAB信号处理之离散时间系统的时域分析
  8. Python 列表下标操作
  9. win7安装python3.6_Win7 64位下python3.6.5安装配置图文教程
  10. python课程报告模板_Python制作WORD报告
  11. Lecture 3:动态规划
  12. VC运行库合集下载,含VC2005/2008/2010/2012/2013
  13. oracle的oem登录,如何启动Oracle的OEM管理工具?
  14. 服务器主板检测卡显示06,主板检测卡代码大全对照表
  15. 有道翻译 vs google翻译
  16. VMware Workstation 与 Device/Credential Guard 不兼容.在禁用 Device/Credenti
  17. ①变量、常量、数据类型解释 ②标识符命原则 ③sizeof使用原则 ④float型科学计数法 ⑤字符转换到ASCII表 ⑥\t 的使用意义【黑马程序员视频】
  18. java多线程之线程安全----铁路售票系统的实现
  19. String的普通方法
  20. 软件盗版与非商业使用

热门文章

  1. matlab 中try/catch语句
  2. java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory的解决(转)
  3. php移动文件的函数 move_uploaded_file()和copy
  4. Feign 集成 Hystrix实现不同的调用接口不同的设置
  5. java成员方法tostring_Java 工具类-toString
  6. 最常用的springmvc注解使用技巧
  7. MySql 5.7.2搭建主从(master/slave)复制
  8. MyCat分片规则之一致性hash分片
  9. servlet 之forward和sendRedirect跳转
  10. 04-jQuery的属性操作