Commit d8677412 authored by Michael's avatar Michael

added yaml config external configuration

parent ceedb9eb
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Java",
"type": "java",
"request": "launch",
"stopOnEntry": true,
"jdkPath": "${env:JAVA_HOME}/bin",
"cwd": "${fileDirname}",
"startupClass": "${fileBasenameNoExtension}",
"classpath": [
".",
"${fileDirname}"
]
},
{
"name": "Java Console App",
"type": "java",
"request": "launch",
"stopOnEntry": true,
"jdkPath": "${env:JAVA_HOME}/bin",
"cwd": "${fileDirname}",
"startupClass": "${fileBasenameNoExtension}",
"classpath": [
".",
"${fileDirname}"
],
"externalConsole": true
},
{
"type": "java",
"name": "Debug (Launch)-Application<spring-demo>",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "demo.Application",
"projectName": "spring-demo",
"args": ""
},
{
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "localhost",
"port": 0
}
]
}
\ No newline at end of file
......@@ -2,4 +2,4 @@ FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
ADD ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
\ No newline at end of file
ENTRYPOINT ["java","-Dspring.profiles.active=${stage}", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
\ No newline at end of file
# TODO
\ No newline at end of file
# TODO
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
\ No newline at end of file
foo=Mustermann
\ No newline at end of file
foo=bar
\ No newline at end of file
......@@ -5,6 +5,7 @@ services:
image: rootknecht.net/spring-demo:latest
environment:
- foo=bar
- stage=prod
env_file:
- ./conf/data.env
ports:
......
package demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class Application {
@Value("${foo:default_value}")
private String awesome;
@ConfigurationProperties(prefix="bar")
public class barProperties {
private String firstName;
public String getFirstName() {
return this.firstName;
}
// Simple Environment-Value
// Can be overwritten in docker-compose
@Value("${foo:default_value}")
private String foo;
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Autowired
private ApplicationProperties applicationProperties;
}
@RequestMapping("/")
public String home() {
barProperties b = new barProperties();
return "Hello " + awesome + " " + b.getFirstName();
return "Hello " + foo + "<br>" + applicationProperties;
}
public static void main(String[] args) {
......
package demo;
import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties("server")
public class ApplicationProperties {
private String email;
private List<Cluster> cluster = new ArrayList<>();
public static class Cluster {
private String ip;
private String path;
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
@Override
public String toString() {
return "Cluster{" +
"ip='" + ip + '\'' +
", path='" + path + '\'' +
'}';
}
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public List<Cluster> getCluster() {
return cluster;
}
public void setCluster(List<Cluster> cluster) {
this.cluster = cluster;
}
@Override
public String toString() {
return "ServerProperties{" +
"email='" + email + '\'' +
", cluster=" + cluster +
'}';
}
}
\ No newline at end of file
logging:
level:
.: error
org.springframework: ERROR
com.mkyong: ERROR
spring:
profiles:
# active: "dev"
# include: "prod"
main:
banner-mode: "off"
server:
port: 8080
email: default@rootknecht.net
---
#TODO: figure out why I need this here and in bootstrap.yml
spring:
application:
name: testLatticeApp
profiles: dev
server:
email: dev@rootknecht.net
cluster:
- ip: 127.0.0.1
path: /dev1
- ip: 127.0.0.2
path: /dev2
- ip: 127.0.0.3
path: /dev3
ribbon:
ServerListRefreshInterval: 1000
---
endpoints:
health:
sensitive: false
restart:
enabled: true
shutdown:
enabled: true
\ No newline at end of file
spring:
profiles: prod
server:
email: prod@rootknecht.net
cluster:
- ip: 192.168.0.1
path: /app1
- ip: 192.168.0.2
path: /app2
- ip: 192.168.0.3
path: /app3
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment