Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ repositories {

dependencies {
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.projectlombok:lombok:1.18.30")
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.javaspringcourse.config;

import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.javaspringcourse.config.property.MinecraftServerStartProp;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Log4j2
@Configuration
@EnableConfigurationProperties(MinecraftServerStartProp.class)
@RequiredArgsConstructor
public class MinecraftServerStartConfig {
private final MinecraftServerStartProp minecraftServerStartProp;

@Bean
@Profile("test")
public String testServerChecker() {
log.info("Running testServerChecker...");
return "testServerChecker";
}

@Bean
@ConditionalOnBean(name = "testServerChecker")
public String testServerProfiler() {
log.info("Running testServerProfiler...");
return "testServerChecker";
}

@Bean
@ConditionalOnExpression("'${server.env-var}' != 'default'")
public String specialServerMode() {
log.info("Running specialServerMode...");
log.warn("GEORGE DROID ©NEGROTECH 2077 joined the server.");
return "specialServerMode";
}

@PostConstruct
public void init() {
log.info("Server Name: {}", minecraftServerStartProp.getName());
log.info("Server Params: {}", minecraftServerStartProp.getStartParams());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.javaspringcourse.config.property;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;

@Data
@ConfigurationProperties(prefix = "server.start")
public class MinecraftServerStartProp {
String name;
List<String> startParams;
}
8 changes: 8 additions & 0 deletions src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
server:
start:
name: svo-craft-dev
startParams:
- debug
- infiniteWar
- nobodyWins
env-var: ${env-var:default}
7 changes: 7 additions & 0 deletions src/main/resources/application-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
server:
start:
name: svo-craft-dev
startParams:
- dogovornyachokWillBe
- trumpWins
env-var: ${env-var:specialVal}
8 changes: 8 additions & 0 deletions src/main/resources/application-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
server:
start:
name: svo-craft-dev
startParams:
- debug
- checkDogovornyachok
- nobodyWins
env-var: ${env-var:default}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env-var должен заполняться из переменной окружения, если переменной нет, то ставить значение по умочланию default. Имена переменных окружений указываются в верхнем регистре

1 change: 0 additions & 1 deletion src/main/resources/application.properties

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spring:
application:
name: java-spring-course