色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

使用SpringBoot自定義starter詳解

瀏覽:95日期:2023-03-12 11:22:47
一、新建一個工程

工程由xxx-sprig-boot-starter和xxx-sprig-boot-starter-configure兩個模塊組成;

使用SpringBoot自定義starter詳解

xxx-sprig-boot-starter模塊

只用來做依賴導入 依賴于 xxx-sprig-boot-starter-configure模塊,沒有實際代碼

<?xml version='1.0' encoding='UTF-8'?><project xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd'> <modelVersion>4.0.0</modelVersion> <groupId>com.ander</groupId> <artifactId>ander-spring-boot-starter</artifactId> <version>1.0-SNAPSHOT</version> <!--依賴ander-spring-boot-starter-configure工程--> <dependencies><dependency> <groupId>com.ander</groupId> <artifactId>ander-spring-boot-starter-configure</artifactId> <version>0.0.1-SNAPSHOT</version></dependency> </dependencies></project>

使用SpringBoot自定義starter詳解

xxx-sprig-boot-starter-configure模塊

專門自動配置模塊 依賴于spring-boot-starter-web

<?xml version='1.0' encoding='UTF-8'?><project xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd'> <modelVersion>4.0.0</modelVersion> <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.10.RELEASE</version><relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.ander</groupId> <artifactId>ander-spring-boot-starter-configure</artifactId> <version>0.0.1-SNAPSHOT</version> <name>ander-spring-boot-starter-configure</name> <description>Demo project for Spring Boot</description> <properties><java.version>1.8</java.version> </properties><dependencies><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency> </dependencies></project>

使用SpringBoot自定義starter詳解

二、xxx-sprig-boot-starter-configure模塊自動配置編碼2.1 服務層編碼

/** * Service層 * * @Author: Ander * @Date: 2021-05-04 */public class HelloService { private HelloServiceProperties helloServiceProperties; public String helloService(String name) {return helloServiceProperties.getPrefix() + ' '+ name + ' ' + helloServiceProperties.getSuffix(); } public HelloServiceProperties getHelloServiceProperties() {return helloServiceProperties; } public void setHelloServiceProperties(HelloServiceProperties helloServiceProperties) {this.helloServiceProperties = helloServiceProperties; }}2.2 屬性配置類編碼

/** * 屬性配置類 * * @Author: Ander * @Date: 2021-05-04 */@ConfigurationProperties(prefix = 'com.ander')public class HelloServiceProperties { private String prefix = 'hi'; private String suffix = 'hello world'; public String getPrefix() {return prefix; } public void setPrefix(String prefix) {this.prefix = prefix; } public String getSuffix() {return suffix; } public void setSuffix(String suffix) {this.suffix = suffix; }}2.3 starter自動配置類編碼

@EnableConfigurationProperties({HelloServiceProperties.class})作用:讓xxxProperties生效加入到容器中

/** * 自定義starter自動配置類 * * @Author: Ander * @Date: 2021-05-04 */@Configuration@ConditionalOnWebApplication // 指定web應用才生效@EnableConfigurationProperties({HelloServiceProperties.class})public class HelloServiceAutoConfigure { @Autowired private HelloServiceProperties helloServiceProperties; @Bean public HelloService helloService() {HelloService helloService = new HelloService();helloService.setHelloServiceProperties(helloServiceProperties);return helloService; }}2.4 添加自動配置類到META-INF路徑下

使用SpringBoot自定義starter詳解

2.5 將工程安裝到本地

注意先安裝xxx-spring-boot-starter-configure,再安裝xxx-spring-boot-starter

使用SpringBoot自定義starter詳解

三、新建一個工程測試自定義starter3.1 編寫controller層

/** * starter測試控制類 * * @Author: Ander * @Date: 2021-05-05 */@RestControllerpublic class StarterTestController { @Autowired private HelloService helloService; @GetMapping('hello') public String hello(String name) {return helloService.helloService(name); }}3.2 編寫配置文件

server.port=8888com.ander.prefix=HIcom.ander.suffix=HELLO WORLD

四、測試結果4.1 使用starter默認配置

使用SpringBoot自定義starter詳解

4.2 使用自定義配置

使用SpringBoot自定義starter詳解

到此這篇關于使用Spring Boot自定義starter詳解的文章就介紹到這了,更多相關Spring Boot自定義starter內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 免费国产成人高清视频网站 | 中国一级毛片欧美一级毛片 | 午夜无遮挡怕怕怕免费视频 | 三级香蕉| 日本免费一区二区三区三州 | 日本护士一级毛片在线播放 | 欧美一区二区三区久久综合 | 日韩精品一区二区三区在线观看 | xo欧美性另类 | 国产成人免费高清激情视频 | 国产一级一片免费播放刺激 | 最近手机高清中文字幕大全7 | 曰韩一级| 色吊丝avav色吊丝 | 精品综合久久久久久99 | 呦女精品视频 | 99视频精品全国免费 | 日本免费一区二区三区毛片 | 国产一区二区在免费观看 | 夜夜爱夜夜爽夜夜做夜夜欢 | 伊人色综合久久天天人手人停 | 一区在线免费观看 | 国产午夜精品一区二区 | 久久91综合国产91久久精品 | 精品国产成a人在线观看 | a欧美| 欧美人与zoxxxx另类9 | 国产成人精品视频一区二区不卡 | 亚洲精品成人 | 黄色三级理论片 | 夜色邦合成福利网站 | 国产一区二区久久精品 | 波多野结衣一区二区三区高清在线 | 国产精品毛片天天看片 | 色综合夜夜嗨亚洲一二区 | 国产成a人片在线观看视频 国产成版人视频网站免费下 | 中文字幕一区二区三区精彩视频 | avtom影院入口永久在线 | 女人张开腿让男人桶视频 | 1717she国产精品免费视频 | 日本人的色道免费网站 |