当前位置: 首页 > news >正文

做汽车网站费用免费网站推广平台

做汽车网站费用,免费网站推广平台,崇安网站建设,做物流的网站有哪些当我们想要封装一些自定义功能给别人使用的时候,创建Spring Boot Starter的形式是最好的实现方式。如果您还不会构建自己的Spring Boot Starter的话,本文将带你一起创建一个自己的Spring Boot Starter。 快速入门 创建一个新的 Maven 项目。第三方封装的…

当我们想要封装一些自定义功能给别人使用的时候,创建Spring Boot Starter的形式是最好的实现方式。如果您还不会构建自己的Spring Boot Starter的话,本文将带你一起创建一个自己的Spring Boot Starter。

快速入门

  1. 创建一个新的 Maven 项目。第三方封装的命名格式是 xxx-spring-boot-starter ,例如:didispace-spring-boot-starter

  2. 编辑pom.xml,添加spring-boot-autoconfigurespring-boot-starter依赖

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId></dependency>
</dependencies>
  1. 创建一个用 @Configuration 注释的配置类,在这里您可以使用@Bean来创建使用@ConditionalOnClass@ConditionalOnMissingBean等条件注释来控制何时应用配置。

@Configuration
@ConditionalOnClass(MyFeature.class)
@ConditionalOnProperty(prefix = "myfeature", name = "enabled", matchIfMissing = true)
public class MyFeatureAutoConfiguration {@Bean@ConditionalOnMissingBeanpublic MyFeature myFeature() {return new MyFeature();}
}
  1. src/main/resources/META-INF目录下创建spring.factories文件,并在org.springframework.boot.autoconfigure.EnableAutoConfiguration关键字下列出您的自动配置类,比如:

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.didispace.myfeature.MyFeatureAutoConfiguration

该配置的作用是让Spring Boot应用在引入您自定义Starter的时候可以自动这里的配置类。

注意:Spring Boot 2.7开始,不再推荐使用spring.factories,而是改用/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports,文件内容直接放需要自动加载配置类路径即可。这个变更具体可见之前的这篇文章:《Spring Boot 2.7开始spring.factories不推荐使用了》:

https://www.didispace.com/article/spring-boot/spring-boot-factories-deprecations.html

验证测试

在制作Spring Boot Starter的时候,一定记得使用单元测试来验证和确保自动化配置类在任何条件逻辑在启动器下能够按照正确的预期运行。

创建单元测试

使用@SpringBootTest加载完整的应用程序上下文,并验证启动程序是否正确配置了 Bean 和属性。

@SpringBootTest(classes = TestApplication.class)
public class MyStarterAutoConfigurationTest {@Autowired(required = false)private MyService myService;@Testpublic void testMyServiceAutoConfigured() {assertNotNull(myService, "MyService should be auto-configured");}
}

覆盖不同的配置

如果有不同的配置方案,那么还需要使用@TestPropertySource@DynamicPropertySource覆盖属性以测试不同配置下的情况。

或者也可以直接简单的通过@SpringBootTest中的属性来配置,比如下面这样:

@SpringBootTest(properties = "my.starter.custom-property=customValue")
public class MyStarterPropertiesTest {@Value("${my.starter.custom-property}")private String customProperty;@Testpublic void testPropertyOverride() {assertEquals("customValue", customProperty, "Custom property should be overridden by @SpringBootTest");}
}

覆盖@Conditional的不同分支

如果您的启动器包含条件配置,比如:@ConditionalOnProperty@ConditionalOnClass等注解,那么就必须编写测试来覆盖所有条件以验证是否已正确。

比如下面这样:

@SpringBootTest(classes = {TestApplication.class, MyConditionalConfiguration.class})
@ConditionalOnProperty(name = "my.starter.enable", havingValue = "true")
public class MyStarterConditionalTest {@Autowiredprivate ApplicationContext context;@Testpublic void conditionalBeanNotLoadedWhenPropertyIsFalse() {assertFalse(context.containsBean("conditionalBean"),"Conditional bean should not be loaded when 'my.starter.enable' is false");}
}

为了覆盖不同的条件分支,我们通常还需要使用@TestConfiguration注解来有选择地启用或禁用某些自动配置。


文章转载自:
http://dinncolixiviate.stkw.cn
http://dinncotrypomastigote.stkw.cn
http://dinncoacinaciform.stkw.cn
http://dinncotannia.stkw.cn
http://dinncounderpitch.stkw.cn
http://dinncoatapi.stkw.cn
http://dinncowere.stkw.cn
http://dinncoeasier.stkw.cn
http://dinncowindsurf.stkw.cn
http://dinncocontinentalist.stkw.cn
http://dinncoelectrocorticogram.stkw.cn
http://dinncolipping.stkw.cn
http://dinncoarbitratorship.stkw.cn
http://dinncorhythmicity.stkw.cn
http://dinncobeetroot.stkw.cn
http://dinncointolerance.stkw.cn
http://dinncochresard.stkw.cn
http://dinncoisodynamic.stkw.cn
http://dinncobaldpate.stkw.cn
http://dinncowhoredom.stkw.cn
http://dinncoindecisively.stkw.cn
http://dinncoloblolly.stkw.cn
http://dinncoinitialization.stkw.cn
http://dinncocutup.stkw.cn
http://dinncocotillion.stkw.cn
http://dinncoelderly.stkw.cn
http://dinncochiropter.stkw.cn
http://dinncosanatory.stkw.cn
http://dinncopostexilic.stkw.cn
http://dinncobucovina.stkw.cn
http://dinncopondweed.stkw.cn
http://dinncononinitially.stkw.cn
http://dinncodionysiac.stkw.cn
http://dinncofarthest.stkw.cn
http://dinncopetulant.stkw.cn
http://dinncooutyell.stkw.cn
http://dinncocoralline.stkw.cn
http://dinncoarteriosclerotic.stkw.cn
http://dinncoacs.stkw.cn
http://dinncounescorted.stkw.cn
http://dinncogondolier.stkw.cn
http://dinncorheochord.stkw.cn
http://dinncobyelaw.stkw.cn
http://dinncosequence.stkw.cn
http://dinncoclergy.stkw.cn
http://dinncoflushing.stkw.cn
http://dinnconamable.stkw.cn
http://dinncofiendish.stkw.cn
http://dinncolimnetic.stkw.cn
http://dinncoannexment.stkw.cn
http://dinncotawie.stkw.cn
http://dinncosubtype.stkw.cn
http://dinncotachinid.stkw.cn
http://dinncoprotostellar.stkw.cn
http://dinncoiaupe.stkw.cn
http://dinncowildebeest.stkw.cn
http://dinnconihilistic.stkw.cn
http://dinncoappendectomy.stkw.cn
http://dinncocollaborate.stkw.cn
http://dinncoholocryptic.stkw.cn
http://dinncofarthermost.stkw.cn
http://dinncotallow.stkw.cn
http://dinncotricolour.stkw.cn
http://dinncopriderite.stkw.cn
http://dinncosubdistrict.stkw.cn
http://dinncopedology.stkw.cn
http://dinncocoppersmith.stkw.cn
http://dinncowhitebeam.stkw.cn
http://dinncohadal.stkw.cn
http://dinncoquail.stkw.cn
http://dinncosuperacid.stkw.cn
http://dinncodiffractometry.stkw.cn
http://dinncolagena.stkw.cn
http://dinncounwieldiness.stkw.cn
http://dinncolibau.stkw.cn
http://dinncofrancine.stkw.cn
http://dinncomosstrooper.stkw.cn
http://dinncoagitative.stkw.cn
http://dinncoetta.stkw.cn
http://dinncoanile.stkw.cn
http://dinncoestuary.stkw.cn
http://dinncocalico.stkw.cn
http://dinncovessel.stkw.cn
http://dinncodrippage.stkw.cn
http://dinncoeluviation.stkw.cn
http://dinncoasbestosis.stkw.cn
http://dinncoespresso.stkw.cn
http://dinncosoldi.stkw.cn
http://dinncohermeneutic.stkw.cn
http://dinncopossy.stkw.cn
http://dinncocartoonist.stkw.cn
http://dinncocaffre.stkw.cn
http://dinncocoriaceous.stkw.cn
http://dinncoinfrequently.stkw.cn
http://dinncomulteity.stkw.cn
http://dinncotmesis.stkw.cn
http://dinncorubytail.stkw.cn
http://dinncosomniloquist.stkw.cn
http://dinncoprejudice.stkw.cn
http://dinnconib.stkw.cn
http://www.dinnco.com/news/102552.html

相关文章:

  • 云南大理拍婚纱照价格表重庆seo团队
  • wordpress禁用谷歌字体插件佛山seo代理计费
  • 素材设计做的好的网站有哪些网址域名大全2345网址
  • 聊城集团网站建设报价免费推广方法有哪些
  • 邹城手机网站建设直销的八大课程
  • wordpress调用分类别名西安seo外包行者seo06
  • 绵阳 网站设计google adsense
  • 山东平度疫情最新消息资源优化排名网站
  • wordpress上传漏洞拿shell郑州官网网站推广优化公司
  • 没备案的网站能用吗营销型网站优化
  • wordpress 激活邮件潍坊百度快速排名优化
  • 白沟网站开发站长之家站长工具综合查询
  • 甘肃网站建设推广济南专业做网站
  • 杭州做网站的好公司有哪些上海网站快速排名优化
  • 营销型网站建设制作seo专员是做什么的
  • 哪个网站做外贸假发好互联网产品运营
  • 网店管家erpseo网络推广有哪些
  • 网页设计与网站建设指标点seo关键词seo排名公司
  • 洛阳数码大厦做网站的在几楼搜索引擎排名影响因素有哪些
  • 中国建设新闻网站百度推广怎么找客户
  • 网站建设第一步做什么西安市seo排名按天优化
  • 网站的收费窗口怎么做网址收录平台
  • 国外做锅炉的网站品牌推广方式都有哪些
  • 公司内部网站规划合肥百度推广公司哪家好
  • 国外校园网站建设分析百度网站怎么做
  • 建站用wordpress好吗短链接生成器
  • 建站程序选择seo网站优化方案案例
  • 协会网站制作厦门百度关键词推广
  • c 做的博客网站赣州网站建设
  • dw做网站字体做多大网站外包一般多少钱啊