Spring boot service name (#8006)
resolves #7998 --------- Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com> Co-authored-by: Lauri Tulmin <ltulmin@splunk.com>
This commit is contained in:
parent
5a0e2cb765
commit
d6271cccc7
|
@ -178,14 +178,16 @@ public class SpringBootServiceNameDetector implements ConditionalResourceProvide
|
|||
try {
|
||||
LoadSettings settings = LoadSettings.builder().build();
|
||||
Load yaml = new Load(settings);
|
||||
Map<String, Object> data = (Map<String, Object>) yaml.loadFromInputStream(in);
|
||||
Map<String, Map<String, Object>> spring =
|
||||
(Map<String, Map<String, Object>>) data.get("spring");
|
||||
if (spring != null) {
|
||||
Map<String, Object> app = spring.get("application");
|
||||
if (app != null) {
|
||||
Object name = app.get("name");
|
||||
return (String) name;
|
||||
for (Object o : yaml.loadAllFromInputStream(in)) {
|
||||
Map<String, Object> data = (Map<String, Object>) o;
|
||||
Map<String, Map<String, Object>> spring =
|
||||
(Map<String, Map<String, Object>>) data.get("spring");
|
||||
if (spring != null) {
|
||||
Map<String, Object> app = spring.get("application");
|
||||
if (app != null) {
|
||||
Object name = app.get("name");
|
||||
return (String) name;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
|
|
|
@ -75,6 +75,16 @@ class SpringBootServiceNameDetectorTest {
|
|||
expectServiceName(result, "cat-store");
|
||||
}
|
||||
|
||||
@Test
|
||||
void classpathApplicationYamlContainingMultipleYamlDefinitions() {
|
||||
when(system.openClasspathResource(APPLICATION_YML))
|
||||
.thenReturn(
|
||||
ClassLoader.getSystemClassLoader().getResourceAsStream("application-multi.yml"));
|
||||
SpringBootServiceNameDetector guesser = new SpringBootServiceNameDetector(system);
|
||||
Resource result = guesser.createResource(config);
|
||||
expectServiceName(result, "cat-store");
|
||||
}
|
||||
|
||||
@Test
|
||||
void yamlFileInCurrentDir() throws Exception {
|
||||
Path yamlPath = Paths.get(APPLICATION_YML);
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
flib:
|
||||
something:
|
||||
12
|
||||
|
||||
section:
|
||||
two: 2
|
||||
|
||||
server:
|
||||
port: 777
|
||||
context-path: /meow
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: cat-store
|
||||
|
||||
---
|
||||
some:
|
||||
other:
|
||||
property: value
|
Loading…
Reference in New Issue