Skip to content

Instantly share code, notes, and snippets.

@fionera
Created September 6, 2020 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fionera/b35aefffc6568c1d883da433416a7686 to your computer and use it in GitHub Desktop.
Save fionera/b35aefffc6568c1d883da433416a7686 to your computer and use it in GitHub Desktop.
Spring Boot Example for Bukkit Plugins
package de.fionera.springboottest;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.SmartLifecycle;
public class DemoApplication implements ApplicationRunner, SmartLifecycle {
private boolean isRunning;
@Override
public void run(ApplicationArguments args) {
System.out.println("Hello World");
}
@Override
public void start() {
System.out.println("Start");
isRunning = true;
}
@Override
public void stop() {
System.out.println("Stop");
isRunning = false;
}
@Override
public boolean isRunning() {
return isRunning;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.fionera</groupId>
<artifactId>spring-boot-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Spring Boot Test</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
</dependencies>
</project>
package de.fionera.springboottest;
import org.bukkit.plugin.java.JavaPlugin;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
public final class SpringBootTest extends JavaPlugin {
private ConfigurableApplicationContext context;
@Override
public void onLoad() {
context = SpringApplication.run(DemoApplication.class);
}
@Override
public void onEnable() {
context.start();
}
@Override
public void onDisable() {
context.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment