Fix GitCommitId example

This commit is contained in:
Grzegorz Piwowarek 2016-08-15 11:47:01 +02:00
parent ad9986874f
commit c2e999f09f
2 changed files with 18 additions and 6 deletions

View File

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

View File

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