- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有好question关于添加多个 tomcat 连接器并将它们分别绑定(bind)到单独的 Controller 的能力。
安迪·威尔金森 (Andy Wilkinson) 的好答案的精髓就在这里:
public static void main(String[] args) {
SpringApplicationBuilder parentBuilder
= new SpringApplicationBuilder(ApplicationConfiguration.class);
parentBuilder.child(ServiceOneConfiguration.class)
.properties("server.port:8080").run(args);
parentBuilder.child(ServiceTwoConfiguration.class)
.properties("server.port:8081").run(args);
}
我想继续讨论并问另一个问题:
有没有办法让每个子应用程序上下文读取一些子特定应用程序属性,并支持所有标准 spring-boot 的功能,例如配置文件后缀文件名等。
拥有三个独立的属性文件:
application.properties
child1.properties
child2.properties
并且能够为每个上下文设置一个文件。
但对我来说重要的是它们必须支持所有 spring-boot 魔法。例如,如果我像传递命令行参数 --spring.profiles.active=dev
一样激活新的配置文件,那么不仅应该自动加载这三个文件(每个上下文一个),还应该加载另一组文件文件(如果存在)也应该自动加载:
application-dev.properties
child1-dev.properties
child2-dev.properties
当然,应该按照定义的顺序等在标准 spring-boot 支持的路径中搜索这些文件。
如果盒子里有一些编码,是否有可能?
只有一个 application.properties
文件(支持配置文件等),但以某种方式将带前缀的属性映射到子上下文的无前缀属性。
示例:
child1.server.port=8081
child1.foo=bar
child2.server.port=8082
child2.foo=baz
第一个子上下文应该看到这些属性,就像它们只是:
server.port=8081
foo=bar
第二个子上下文应该看到这些属性,就像它们只是:
server.port=8082
foo=baz
因此,标准 spring-boot 的自动配置将起作用并正确设置 tomcat 的端口等。
<小时/>我并不是在寻找特定的方法(但如果你问我,我倾向于第二种方法),但是任何开箱即用的工作或可以用最小的条件方法实现的工作都足以满足我的需要。
最佳答案
您可以使用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
分别配置服务一和服务二。
例如,在 child1.properties
中使用 server.port=8081
,在 child2.properties 中使用
,当启动在两个子服务中使用自动配置并且依赖于 server.port=8082
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: default
2019-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: default
2019-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 WebApplicationContext
2019-01-22 13:38:10.668 INFO 80968 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 612 ms
2019-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: default
2019-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 WebApplicationContext
2019-01-22 13:38:11.101 INFO 80968 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 97 ms
2019-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)
关于java - 多上下文 spring-boot 应用程序 : how to define standard spring-boot properties for each child context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54308472/
我正在尝试加载外部 SVG 并将其附加到 Electron 项目中的现有 SVG。 d3.xml 方法对我不起作用,所以我正在查看 d3.symbols ,希望如果我提供路径数据(来自 fs.read
我正在编写一个 Web 应用程序,使用 Go 作为后端。我正在使用这个 GraphQL 库 (link)和 Echo Web 框架 (link) .问题在于 graphql-go 库在 Go 中使用了
有没有办法改造 gin.Context至 context.Context在围棋?构建 Go 微服务应该使用什么? 最佳答案 标准库的 context.Context type 是一个接口(interf
如果我能够像这样注册一个接收器: LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new Inte
如果我有 appengine.Context 而不是 ,我不知道如何调用 cloud.WithContext 和 google.DefaultClient >上下文。上下文。 有(旧的)“appeng
有什么区别- AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SER
我刚读了这篇文章:Build You Own Web Framework In Go为了在处理程序之间共享值,我选择了 context.Context我通过以下方式使用它在处理程序和中间件之间共享值:
在 Visual Studio Code 中,我对 3 个“上下文”菜单项感到非常困惑:Run Tests in Context和 Debug Tests in Context和 Run .NET C
我正在使用带有 和 @Autowired 的 Spring 2.5.6 版本。 虽然我在调度程序上下文中使用 SimpleUrlHandlerMapping ,但一切正常 - Autowiring 工
我使用的是 Context.registerReceiver()、Context.sendBroadcast(Intent) 和 Context.unregisterReceiver() 但是当我看到
问题在于以下错误, [错误] 在 scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4580)[错误] 在 scal
最近我正在尝试使用 SoundPool 在我的应用程序中播放一些简单的音效 但不幸的是它在 AVD 中不起作用并且应用程序崩溃 “上下文”到底是什么意思? 完全不懂 提前致谢 最佳答案 任何上下文都允
我正在使用上下文建议器,我想知道我们是否可以设置用于建议的上下文范围,而不是使用所有上下文。 目前查询需要匹配所有上下文。我们能否在上下文中添加“或”运算和/或指定用于特定查询的上下文? 以here为
我被一个使用这种方法的函数卡住了。所以我知道如何使用 expressionValue(with:context:) 函数,但上下文如何参与对我来说仍然是不透明的。也许有人有简单的例子? try tra
我正在尝试在上下文管理器中更改我的 python 程序中的目录。使用 invoke.context.Context 似乎是正确的方法,从 Fabric 文档中获取并且使用常规 with os.chdi
我最近开始使用 Android Studio 处理我的 Android 项目。我注意到在 IDE 的右下角,有文本 Context: .好奇心打败了我,所以现在我正在网上搜索更多信息。我还没有找到任
假设我有这些功能: func A(ctx context.Context) { // A takes some time to process } func B(ctx context.Con
所以,我有一个 context.Context( https://golang.org/pkg/context/ ) 变量,有没有办法列出这个变量包含的所有键? 最佳答案 可以使用不安全反射列出 co
我正在尝试找出传播 context.Context 的正确方法用于在使用 Gin 时使用 OpenTelemetry 进行跟踪。 我目前有一个 gin调用函数并传递 *gin.Context 的处理程
我们可以使用 Remove["context`*"] 删除特定上下文中的所有符号。 .但是是否可以删除 "context`"自己从系统中删除,以便它不再在 Contexts[] 中列出? 最佳答案 据
我是一名优秀的程序员,十分优秀!