BAEL-3499 Added files for article (#8498)

This commit is contained in:
Priyesh Mashelkar
2020-01-09 18:14:56 +00:00
committed by Grzegorz Piwowarek
parent 7a186e9bc8
commit 56f11da504
6 changed files with 81 additions and 2 deletions
@@ -0,0 +1,18 @@
package com.baeldung.buildproperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;
@SpringBootApplication
@ComponentScan(basePackages = "com.baeldung.buildproperties")
@PropertySource("classpath:build.properties")
//@PropertySource("classpath:build.yml")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@@ -0,0 +1,21 @@
package com.baeldung.buildproperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
public class BuildInfoService {
@Value("${application-description}")
private String applicationDescription;
@Value("${application-version}")
private String applicationVersion;
public String getApplicationDescription() {
return applicationDescription;
}
public String getApplicationVersion() {
return applicationVersion;
}
}
@@ -0,0 +1,2 @@
application-description=@project.description@
application-version=@project.version@
+2
View File
@@ -0,0 +1,2 @@
application-description: ^project.description^
application-version: ^project.version^
@@ -0,0 +1,24 @@
package com.baeldung.buildproperties;
import static org.junit.Assert.assertThat;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
class BuildInfoServiceIntegrationTest {
@Autowired
private BuildInfoService service;
@Test
void whenGetApplicationDescription_thenSuccess() {
assertThat(service.getApplicationDescription(), Matchers.is("This is simple boot application for Spring boot actuator test"));
assertThat(service.getApplicationVersion(), Matchers.is("0.0.1-SNAPSHOT"));
}
}