栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

多上下文spring-boot应用程序:如何为每个子上下文定义标准spring-boot属性

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

多上下文spring-boot应用程序:如何为每个子上下文定义标准spring-boot属性

您可以使用

spring.config.name
以下方法实现第一个建议:

public static void main(String[] args) {    SpringApplicationBuilder parentBuilder = new SpringApplicationBuilder(ParentApplication.class)         .web(WebApplicationType.NONE);    parentBuilder.run(args);    parentBuilder.child(ServiceOneConfiguration.class) .properties("spring.config.name=child1").run(args);    parentBuilder.child(ServiceTwoConfiguration.class) .properties("spring.config.name=child2").run(args);}

然后

child1{-profile}.properties
,您可以分别使用和
child2{-profile}.properties
配置服务一和服务二。

例如,使用

server.port=8081
in
child1.properties
server.port=8082
in
child2.properties
,在两个子服务中启动使用自动配置的应用程序时,您应该看到类似于以下内容的输出
spring-boot-starter-web

  .   ____          _ __ _ _ /\ / ___'_ __ _ _(_)_ __  __ _    ( ( )___ | '_ | '_| | '_ / _` |     \/  ___)| |_)| | | | | || (_| |  ) ) ) )  '  |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot ::        (v2.1.2.RELEASE)2019-01-22 13:38:09.690  INFO 80968 --- [main] com.example.parent.ParentApplication     : Starting ParentApplication on …2019-01-22 13:38:09.692  INFO 80968 --- [main] com.example.parent.ParentApplication     : No active profile set, falling back to default profiles: default2019-01-22 13:38:09.842  INFO 80968 --- [main] com.example.parent.ParentApplication     : Started ParentApplication in 0.371 seconds (JVM running for 0.644)  .   ____          _ __ _ _ /\ / ___'_ __ _ _(_)_ __  __ _    ( ( )___ | '_ | '_| | '_ / _` |     \/  ___)| |_)| | | | | || (_| |  ) ) ) )  '  |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot ::        (v2.1.2.RELEASE)2019-01-22 13:38:10.046  INFO 80968 --- [main] com.example.parent.ParentApplication     : No active profile set, falling back to default profiles: default2019-01-22 13:38:10.584  INFO 80968 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (http)2019-01-22 13:38:10.604  INFO 80968 --- [main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]2019-01-22 13:38:10.605  INFO 80968 --- [main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.14]2019-01-22 13:38:10.613  INFO 80968 --- [main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/awilkinson/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]2019-01-22 13:38:10.668  INFO 80968 --- [main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext2019-01-22 13:38:10.668  INFO 80968 --- [main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 612 ms2019-01-22 13:38:10.829  INFO 80968 --- [main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'2019-01-22 13:38:10.981  INFO 80968 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8081 (http) with context path ''2019-01-22 13:38:10.981  INFO 80968 --- [main] com.example.parent.ParentApplication     : Started ParentApplication in 0.955 seconds (JVM running for 1.784)  .   ____          _ __ _ _ /\ / ___'_ __ _ _(_)_ __  __ _    ( ( )___ | '_ | '_| | '_ / _` |     \/  ___)| |_)| | | | | || (_| |  ) ) ) )  '  |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot ::        (v2.1.2.RELEASE)2019-01-22 13:38:11.003  INFO 80968 --- [main] com.example.parent.ParentApplication     : No active profile set, falling back to default profiles: default2019-01-22 13:38:11.093  INFO 80968 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8082 (http)2019-01-22 13:38:11.095  INFO 80968 --- [main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]2019-01-22 13:38:11.096  INFO 80968 --- [main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.14]2019-01-22 13:38:11.100  INFO 80968 --- [main] o.a.c.c.C.[Tomcat-1].[localhost].[/]     : Initializing Spring embedded WebApplicationContext2019-01-22 13:38:11.101  INFO 80968 --- [main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 97 ms2019-01-22 13:38:11.135  INFO 80968 --- [main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'2019-01-22 13:38:11.164  INFO 80968 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8082 (http) with context path ''2019-01-22 13:38:11.165  INFO 80968 --- [main] com.example.parent.ParentApplication     : Started ParentApplication in 0.183 seconds (JVM running for 1.967)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/568715.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号