diff --git a/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java b/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java index b535c8bd4a..95abbf894c 100644 --- a/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java +++ b/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java @@ -2,13 +2,25 @@ package com.baeldung.git; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.PropertySource; +import org.springframework.context.annotation.Bean; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.core.io.ClassPathResource; -@PropertySource(value = "classpath:/git.properties", ignoreResourceNotFound = true) @SpringBootApplication(scanBasePackages = { "com.baeldung.git"}) public class CommitIdApplication { public static void main(String[] args) { SpringApplication.run(CommitIdApplication.class, args); } + + @Bean + public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() { + PropertySourcesPlaceholderConfigurer c = new PropertySourcesPlaceholderConfigurer(); + c.setLocation(new ClassPathResource("git.properties")); + c.setIgnoreResourceNotFound(true); + c.setIgnoreUnresolvablePlaceholders(true); + return c; + } } + + diff --git a/spring-boot/src/test/java/com/baeldung/git/CommitIdTest.java b/spring-boot/src/test/java/com/baeldung/git/CommitIdTest.java index cddc0d60bc..e16791881e 100644 --- a/spring-boot/src/test/java/com/baeldung/git/CommitIdTest.java +++ b/spring-boot/src/test/java/com/baeldung/git/CommitIdTest.java @@ -16,17 +16,17 @@ public class CommitIdTest { private static final Logger LOG = LoggerFactory.getLogger(CommitIdTest.class); - @Value("${git.commit.message.short:#{'UNKNOWN'}}") + @Value("${git.commit.message.short:UNKNOWN}") private String commitMessage; - @Value("${git.branch:#{'UNKNOWN'}}") + @Value("${git.branch:UNKNOWN}") private String branch; - @Value("${git.commit.id:#{'UNKNOWN'}}") + @Value("${git.commit.id:UNKNOWN}") private String commitId; @Test - public void shouldInjectGitInfoProperties() throws Exception { + public void whenInjecting_shouldDisplay() throws Exception { LOG.info(commitId); LOG.info(commitMessage);