Skip to content

Commit 7f9a981

Browse files
author
Ramachandran Nellaiyappan
committed
[feat] home mvc resource updated to display app name and version
1 parent 83e6f01 commit 7f9a981

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.github.nramc.dev.journey.api.config;
2+
3+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
@EnableConfigurationProperties({ApplicationProperties.class})
8+
public class ApplicationContextConfig {
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.github.nramc.dev.journey.api.config;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
5+
@ConfigurationProperties(prefix = "app")
6+
public record ApplicationProperties(
7+
String name,
8+
String version) {
9+
}

src/main/java/com/github/nramc/dev/journey/api/web/resources/mvc/home/HomeResource.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
package com.github.nramc.dev.journey.api.web.resources.mvc.home;
22

3+
import com.github.nramc.dev.journey.api.config.ApplicationProperties;
4+
import lombok.RequiredArgsConstructor;
35
import org.springframework.http.MediaType;
46
import org.springframework.stereotype.Controller;
57
import org.springframework.ui.Model;
68
import org.springframework.web.bind.annotation.GetMapping;
79

810
@Controller
11+
@RequiredArgsConstructor
912
public class HomeResource {
13+
private final ApplicationProperties applicationProperties;
1014

1115
@GetMapping(value = "/", produces = MediaType.TEXT_HTML_VALUE)
1216
public String home(Model model) {
17+
model.addAttribute("applicationProperties", applicationProperties);
1318
return "home";
1419
}
1520

src/main/resources/application.yml

+7
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11

2+
spring:
3+
application:
4+
name: ${app.name}
5+
6+
app:
7+
name: Journey API
8+
version: '@project.version@'

src/main/resources/templates/home.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<title>Hello World</title>
66
</head>
77
<body>
8-
<p>Hello World..!</p>
8+
<p>Hello World..!</p>
9+
<p><span th:text="${applicationProperties.name()}"></span>:<span th:text="${applicationProperties.version()}"></span>
10+
</p>
911
</body>
1012
</html>

0 commit comments

Comments
 (0)