Config
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -59,6 +59,11 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
11
src/main/java/mc/core/Config.java
Normal file
11
src/main/java/mc/core/Config.java
Normal file
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-04-08
|
||||
*/
|
||||
package mc.core;
|
||||
|
||||
public interface Config {
|
||||
int getMaxPlayers();
|
||||
String getDescriptionServer();
|
||||
String getFaviconBase64();
|
||||
}
|
||||
@@ -4,11 +4,18 @@
|
||||
*/
|
||||
package mc.core;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
@Slf4j
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
|
||||
Config config = context.getBean("config", Config.class);
|
||||
|
||||
log.info("Description: {}", config.getDescriptionServer());
|
||||
log.info("Max online: {}", config.getMaxPlayers());
|
||||
log.info("Favicon (base64): {}", config.getFaviconBase64());
|
||||
}
|
||||
}
|
||||
|
||||
37
src/main/java/mc/core/embedded/ConfigFromSpring.java
Normal file
37
src/main/java/mc/core/embedded/ConfigFromSpring.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-04-08
|
||||
*/
|
||||
package mc.core.embedded;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.Config;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
|
||||
@Slf4j
|
||||
@Getter
|
||||
public class ConfigFromSpring implements Config {
|
||||
private String descriptionServer;
|
||||
private String faviconBase64;
|
||||
private int maxPlayers;
|
||||
|
||||
public ConfigFromSpring(String descriptionServer, int maxPlayers, File faviconImageFile) {
|
||||
this.descriptionServer = descriptionServer;
|
||||
this.maxPlayers = maxPlayers;
|
||||
try {
|
||||
faviconBase64 = new String(
|
||||
Base64.getEncoder().encode(
|
||||
FileUtils.readFileToByteArray(faviconImageFile)
|
||||
)
|
||||
);
|
||||
} catch (IOException e) {
|
||||
log.warn("Con't load favicon", e);
|
||||
faviconBase64 = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/icon.png
Normal file
BIN
src/main/resources/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
@@ -2,4 +2,9 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<bean id="config" class="mc.core.embedded.ConfigFromSpring">
|
||||
<constructor-arg index="0" type="java.lang.String" value="MC Core"/>
|
||||
<constructor-arg index="1" type="int" value="100"/>
|
||||
<constructor-arg index="2" type="java.io.File" value="icon.png"/>
|
||||
</bean>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user