Injecting CommitId Into a Spring Bean (#599)
* initial * working * added injection test
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
d81365a7ac
commit
1d511d4336
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.git;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@PropertySource("classpath:/git.properties")
|
||||
@SpringBootApplication(scanBasePackages = { "com.baeldung.git"})
|
||||
public class CommitIdApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CommitIdApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.git;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class CommitInfoController {
|
||||
@Value("${git.commit.message.short}")
|
||||
private String commitMessage;
|
||||
|
||||
@Value("${git.branch}")
|
||||
private String branch;
|
||||
|
||||
@Value("${git.commit.id}")
|
||||
private String commitId;
|
||||
|
||||
@RequestMapping("/commitId")
|
||||
public GitInfoDto getCommitId() {
|
||||
return new GitInfoDto(commitMessage, branch, commitId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.git;
|
||||
|
||||
public class GitInfoDto {
|
||||
private String commitMessage;
|
||||
private String branch;
|
||||
private String commitId;
|
||||
|
||||
public GitInfoDto(String commitMessage, String branch, String commitId) {
|
||||
this.commitMessage = commitMessage;
|
||||
this.branch = branch;
|
||||
this.commitId = commitId;
|
||||
}
|
||||
|
||||
public String getCommitMessage() {
|
||||
return commitMessage;
|
||||
}
|
||||
|
||||
public String getBranch() {
|
||||
return branch;
|
||||
}
|
||||
|
||||
public String getCommitId() {
|
||||
return commitId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user