From e51834c899ff20781295410961934eb06239385c Mon Sep 17 00:00:00 2001 From: Kamal Wickramanayake Date: Sat, 16 May 2026 21:18:32 +0530 Subject: Added spring-boot sample applications --- spring-boot/02-structure/.gitignore | 1 + spring-boot/02-structure/README | 1 + spring-boot/02-structure/pom.xml | 15 +++++++++++++++ .../main/java/com/example/spring/Application.java | 20 ++++++++++++++++++++ .../com/example/spring/hello/HelloController.java | 19 +++++++++++++++++++ .../src/main/resources/application.properties | 10 ++++++++++ .../resources/config/application-default.properties | 1 + .../main/resources/config/application-dev.properties | 1 + .../config/application-production.properties | 0 9 files changed, 68 insertions(+) create mode 100644 spring-boot/02-structure/.gitignore create mode 100644 spring-boot/02-structure/README create mode 100644 spring-boot/02-structure/pom.xml create mode 100644 spring-boot/02-structure/src/main/java/com/example/spring/Application.java create mode 100644 spring-boot/02-structure/src/main/java/com/example/spring/hello/HelloController.java create mode 100644 spring-boot/02-structure/src/main/resources/application.properties create mode 100644 spring-boot/02-structure/src/main/resources/config/application-default.properties create mode 100644 spring-boot/02-structure/src/main/resources/config/application-dev.properties create mode 100644 spring-boot/02-structure/src/main/resources/config/application-production.properties (limited to 'spring-boot/02-structure') diff --git a/spring-boot/02-structure/.gitignore b/spring-boot/02-structure/.gitignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/spring-boot/02-structure/.gitignore @@ -0,0 +1 @@ +target diff --git a/spring-boot/02-structure/README b/spring-boot/02-structure/README new file mode 100644 index 0000000..bcbbb4f --- /dev/null +++ b/spring-boot/02-structure/README @@ -0,0 +1 @@ +In the application.properties file, change the active profile to dev and run to see the difference. diff --git a/spring-boot/02-structure/pom.xml b/spring-boot/02-structure/pom.xml new file mode 100644 index 0000000..17e5390 --- /dev/null +++ b/spring-boot/02-structure/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + + com.example.spring.boot + base-config + 0.0.1-SNAPSHOT + ../00-config + + + structure + + diff --git a/spring-boot/02-structure/src/main/java/com/example/spring/Application.java b/spring-boot/02-structure/src/main/java/com/example/spring/Application.java new file mode 100644 index 0000000..c051033 --- /dev/null +++ b/spring-boot/02-structure/src/main/java/com/example/spring/Application.java @@ -0,0 +1,20 @@ +package com.example.spring; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @SpringBootApplication - Indicates a configuration class that declares one or + * more @Bean methods and also triggers + * auto-configuration and component scanning. This is a + * convenience annotation that is equivalent to + * declaring @Configuration, @EnableAutoConfiguration + * and @ComponentScan. + */ +@SpringBootApplication +public class Application { + + public static void main(String[] args) throws Exception { + SpringApplication.run(Application.class, args); + } +} \ No newline at end of file diff --git a/spring-boot/02-structure/src/main/java/com/example/spring/hello/HelloController.java b/spring-boot/02-structure/src/main/java/com/example/spring/hello/HelloController.java new file mode 100644 index 0000000..ad89d9d --- /dev/null +++ b/spring-boot/02-structure/src/main/java/com/example/spring/hello/HelloController.java @@ -0,0 +1,19 @@ +package com.example.spring.hello; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class HelloController { + + @Value("${my.name}") + private String name; + + @RequestMapping("/") + @ResponseBody + String home() { + return "Hello " + name + "!"; + } +} \ No newline at end of file diff --git a/spring-boot/02-structure/src/main/resources/application.properties b/spring-boot/02-structure/src/main/resources/application.properties new file mode 100644 index 0000000..480ea32 --- /dev/null +++ b/spring-boot/02-structure/src/main/resources/application.properties @@ -0,0 +1,10 @@ +# Possible locations of this file: +# (Properties defined in locations higher in the list override those defined in lower locations) +# +# A /config subdirectory of the current directory +# The current directory +# A classpath /config package +# The classpath root +# + +#spring.profiles.active=dev diff --git a/spring-boot/02-structure/src/main/resources/config/application-default.properties b/spring-boot/02-structure/src/main/resources/config/application-default.properties new file mode 100644 index 0000000..372ce47 --- /dev/null +++ b/spring-boot/02-structure/src/main/resources/config/application-default.properties @@ -0,0 +1 @@ +my.name=ABC diff --git a/spring-boot/02-structure/src/main/resources/config/application-dev.properties b/spring-boot/02-structure/src/main/resources/config/application-dev.properties new file mode 100644 index 0000000..436a73c --- /dev/null +++ b/spring-boot/02-structure/src/main/resources/config/application-dev.properties @@ -0,0 +1 @@ +my.name=ABC DEV! diff --git a/spring-boot/02-structure/src/main/resources/config/application-production.properties b/spring-boot/02-structure/src/main/resources/config/application-production.properties new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3