Skip to content

Commit f956ed0

Browse files
Ranga Rao KaranamRanga Rao Karanam
authored andcommitted
I'm too lazy to put in a comment
1 parent e2b096e commit f956ed0

File tree

56 files changed

+1743
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1743
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
12+
### IntelliJ IDEA ###
13+
.idea
14+
*.iws
15+
*.iml
16+
*.ipr
17+
18+
### NetBeans ###
19+
nbproject/private/
20+
build/
21+
nbbuild/
22+
dist/
23+
nbdist/
24+
.nb-gradle/
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.in28minutes.springboot.tutorial.basics.application.configuration</groupId>
7+
<artifactId>spring-boot-tutorial-basics-configuration</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>spring-boot-tutorial-basics-configuration</name>
12+
<description>Spring Boot Tutorial - Application Configuration with Profiles and YAML</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>2.0.0.M6</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-actuator</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-data-jpa</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-web</artifactId>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-devtools</artifactId>
44+
<scope>runtime</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>com.h2database</groupId>
48+
<artifactId>h2</artifactId>
49+
<scope>runtime</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-starter-test</artifactId>
54+
<scope>test</scope>
55+
</dependency>
56+
</dependencies>
57+
58+
<build>
59+
<plugins>
60+
<plugin>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-maven-plugin</artifactId>
63+
</plugin>
64+
</plugins>
65+
</build>
66+
67+
<repositories>
68+
<repository>
69+
<id>spring-snapshots</id>
70+
<name>Spring Snapshots</name>
71+
<url>https://repo.spring.io/snapshot</url>
72+
<snapshots>
73+
<enabled>true</enabled>
74+
</snapshots>
75+
</repository>
76+
<repository>
77+
<id>spring-milestones</id>
78+
<name>Spring Milestones</name>
79+
<url>https://repo.spring.io/milestone</url>
80+
<snapshots>
81+
<enabled>false</enabled>
82+
</snapshots>
83+
</repository>
84+
</repositories>
85+
86+
<pluginRepositories>
87+
<pluginRepository>
88+
<id>spring-snapshots</id>
89+
<name>Spring Snapshots</name>
90+
<url>https://repo.spring.io/snapshot</url>
91+
<snapshots>
92+
<enabled>true</enabled>
93+
</snapshots>
94+
</pluginRepository>
95+
<pluginRepository>
96+
<id>spring-milestones</id>
97+
<name>Spring Milestones</name>
98+
<url>https://repo.spring.io/milestone</url>
99+
<snapshots>
100+
<enabled>false</enabled>
101+
</snapshots>
102+
</pluginRepository>
103+
</pluginRepositories>
104+
105+
106+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.in28minutes.springboot.tutorial.basics.application.configuration;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
import org.springframework.stereotype.Component;
5+
6+
@Component
7+
@ConfigurationProperties("basic")
8+
public class BasicConfiguration {
9+
private boolean value;
10+
private String message;
11+
private int number;
12+
13+
public boolean isValue() {
14+
return value;
15+
}
16+
17+
public void setValue(boolean value) {
18+
this.value = value;
19+
}
20+
21+
public String getMessage() {
22+
return message;
23+
}
24+
25+
public void setMessage(String message) {
26+
this.message = message;
27+
}
28+
29+
public int getNumber() {
30+
return number;
31+
}
32+
33+
public void setNumber(int number) {
34+
this.number = number;
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.in28minutes.springboot.tutorial.basics.application.configuration;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.context.ApplicationContext;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Profile;
8+
9+
@SpringBootApplication
10+
public class SpringBootTutorialBasicsConfigurationApplication {
11+
12+
public static void main(String[] args) {
13+
ApplicationContext applicationContext = SpringApplication
14+
.run(SpringBootTutorialBasicsConfigurationApplication.class, args);
15+
16+
for (String name : applicationContext.getBeanDefinitionNames()) {
17+
System.out.println(name);
18+
}
19+
}
20+
21+
@Profile("dev")
22+
@Bean
23+
public String devBean() {
24+
return "dev";
25+
}
26+
27+
@Profile("qa")
28+
@Bean
29+
public String qaBean() {
30+
return "qa";
31+
}
32+
33+
@Profile("prod")
34+
@Bean
35+
public String prodBean() {
36+
return "prod";
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.in28minutes.springboot.tutorial.basics.application.configuration;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.beans.factory.annotation.Value;
8+
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
@RestController
13+
public class WelcomeResource {
14+
15+
@Value("${welcome.message}")
16+
private String welcomeMessage;
17+
18+
@GetMapping("/welcome")
19+
public String retrieveWelcomeMessage() {
20+
// Complex Method
21+
return welcomeMessage;
22+
}
23+
24+
@Autowired
25+
private BasicConfiguration configuration;
26+
27+
@RequestMapping("/dynamic-configuration")
28+
public Map<String, Object> dynamicConfiguration() {
29+
// Not the best practice to use a map to store differnt types!
30+
Map<String, Object> map = new HashMap<>();
31+
map.put("message", configuration.getMessage());
32+
map.put("number", configuration.getNumber());
33+
map.put("key", configuration.isValue());
34+
return map;
35+
}
36+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
welcome.message=Welcome message from property file! Welcome to ${app.name} in DEV
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
logging.level.org.springframework: INFO
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
spring.profiles.active=dev
2+
logging.level.org.springframework.web.servlet: DEBUG
3+
app.name=in28Minutes
4+
welcome.message=Welcome message from property file! Welcome to ${app.name}
5+
6+
basic.value: true
7+
basic.message: Dynamic Message
8+
basic.number: 100
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
logging:
2+
level:
3+
org.springframework: INFO
4+
org.springframework.web.servlet: DEBUG
5+
6+
basic:
7+
value: true
8+
message: Dynamic Message YAML
9+
number: 100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.in28minutes.springboot.tutorial.basics.application.configuration;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.test.context.junit4.SpringRunner;
7+
8+
@RunWith(SpringRunner.class)
9+
@SpringBootTest
10+
public class SpringBootTutorialBasicsConfigurationApplicationTests {
11+
12+
@Test
13+
public void contextLoads() {
14+
}
15+
16+
}

0 commit comments

Comments
 (0)