use Placeholder
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package ru.dmitriymx.plugin.config;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BukkitYamlPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
|
||||
|
||||
private final FileConfiguration fileConfiguration;
|
||||
|
||||
public BukkitYamlPlaceholderConfigurer(FileConfiguration fileConfiguration) {
|
||||
this.fileConfiguration = fileConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String resolvePlaceholder(String placeholder, Properties props) {
|
||||
return Optional.ofNullable(fileConfiguration.getString(placeholder))
|
||||
.orElseGet(() -> super.resolvePlaceholder(placeholder, props));
|
||||
}
|
||||
}
|
||||
26
src/main/java/ru/dmitriymx/plugin/config/SpringConfig.java
Normal file
26
src/main/java/ru/dmitriymx/plugin/config/SpringConfig.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package ru.dmitriymx.plugin.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("ru.dmitriymx.plugin")
|
||||
public class SpringConfig {
|
||||
|
||||
@Value("${database.url}")
|
||||
private String databaseUrl;
|
||||
|
||||
@Value("${database.user}")
|
||||
private String databaseUser;
|
||||
|
||||
@Value("${database.password}")
|
||||
private String databasePassword;
|
||||
|
||||
//TODO для демонстрации
|
||||
@Bean("databaseUrl")
|
||||
public String getDatabaseUrl() {
|
||||
return databaseUrl;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user