2
2
.
.
1
1
3
3
.
.
2
2
A
A
s
s
s
s
i
i
g
g
n
n
P
P
r
r
o
o
f
f
i
i
l
l
e
e
-
-
T
T
o
o
a
a
p
p
p
p
l
l
i
i
c
c
a
a
t
t
i
i
o
o
n
n
.
.
p
p
r
r
o
o
p
p
e
e
r
r
t
t
i
i
e
e
s
s
I
I
n
n
f
f
o
o
[
[
R
R
]
]
This tutorial shows how to assign Profile to application-profile1.properties file.
This is used to switch between test and development environments to specify different: host, port, DB.
In this tutorial we will use different application.properties files to specify differet ports 8081 and 8082.
You can't specify multiple Profiles to a single application.properties file (like you can with Classes).
You can't specify for which Profiles to exclude application.properties file (like you can with Classes).
Application will always include application.properties file (for which no Profile is defined).
In this tutorial we will use application.properties file to sepcify Active Profile.
Application Schema [Results]
Spring Boot Starters
GROUP
DEPENDENCY
DESCRIPTION
Web
Spring Web
Enables @Controller and @RequestMapping. Includes Tomcat Server.
application-profile1.properties
application-profile2.properties
application.properties
MyController
P
P
r
r
o
o
c
c
e
e
d
d
u
u
r
r
e
e
Create Project: profiles_applicationproperties (add Spring Boot Starters from the table)
Edit File: application.properties (inside src/main/resources, specifies active Profile)
Create Package: controllers (inside main package)
Create Class: MyController.java (inside controllers package)
Create File: application-profile1.properties (inside src/main/resources, specifies Port 8081)
Create File: application-profile2properties (inside src/main/resources, specifies Port 8082)
application.properties (specifies active Profile)
spring.profiles.active = Profile1
application-profile1.properties (specifies Port 8081)
server.port = 8081
application-profile2properties (specifies Port 8082)
server.port = 8082
MyController.java
package com.ivoronline.profiles_applicationproperties.controllers;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@ResponseBody
@RequestMapping("/Hello")
public String hello() {
return "Hello from Controller";
}
}
R
R
e
e
s
s
u
u
l
l
t
t
s
s
http://localhost:8081/hello
Application Structure
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>