BAEL-3499 Added files for article (#8498)
This commit is contained in:
parent
7a186e9bc8
commit
56f11da504
@ -7,16 +7,17 @@
|
||||
<name>spring-boot</name>
|
||||
<packaging>war</packaging>
|
||||
<description>This is simple boot application for Spring boot actuator test</description>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
|
||||
<!-- JUnit Jupiter dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
@ -198,6 +199,16 @@
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<configuration>
|
||||
<delimiters>
|
||||
<delimiter>@</delimiter>
|
||||
</delimiters>
|
||||
<useDefaultDelimiters>false</useDefaultDelimiters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
@ -251,6 +262,7 @@
|
||||
<graphql-java-tools.version>5.2.4</graphql-java-tools.version>
|
||||
<guava.version>18.0</guava.version>
|
||||
<git-commit-id-plugin.version>2.2.4</git-commit-id-plugin.version>
|
||||
<resource.delimiter>@</resource.delimiter>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
2
spring-boot/src/main/resources/build.properties
Normal file
2
spring-boot/src/main/resources/build.properties
Normal file
@ -0,0 +1,2 @@
|
||||
application-description=@project.description@
|
||||
application-version=@project.version@
|
2
spring-boot/src/main/resources/build.yml
Normal file
2
spring-boot/src/main/resources/build.yml
Normal 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"));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user