BAEL-3499 Moved code to spring-boot-properties (#8643)
This commit is contained in:
parent
3b4c813b43
commit
6dcb329bbc
@ -6,6 +6,7 @@
|
||||
<name>spring-boot-properties</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Spring Boot Properties Module</description>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
@ -64,6 +65,19 @@
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<configuration>
|
||||
<delimiters>
|
||||
<delimiter>@</delimiter>
|
||||
</delimiters>
|
||||
<useDefaultDelimiters>false</useDefaultDelimiters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
@ -106,6 +120,7 @@
|
||||
<commons-configuration.version>1.10</commons-configuration.version>
|
||||
<guava.version>20.0</guava.version>
|
||||
<httpcore.version>4.4.11</httpcore.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;
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
application-version=@project.version@
|
@ -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