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:
adamleantech 2023-04-02 02:58:43 +01:00 committed by GitHub
parent 5a0e2cb765
commit d6271cccc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 8 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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