mcspring-boot
mcspring-boot copied to clipboard
Add support for multiple plugins using MCSpring-boot by letting them piggyback on the same spring context
It would be nice if you could provide a plugin that supplies a spring context and allows you to specify packages that the autoconfig scanner should look for (which in turn can have @ComponentScan
annotations). Something like this:
package my.package.name;
import dev.alangomes.springspigot.MCSpringBoot;
class MyPlugin extends JavaPlugin {
public void onLoad(){
MCSpringBoot.addAutoConfigurationPath("my.package.name.config");
}
...
public void onEnable(){
if(MCSpringBoot.isRunning()){
MCSpringBoot.run();
}
MyBeanClass bean = MCSpringBoot.getContext()
.getBean("myBeanName", MyBeanClass.class)
}
}
package my.package.name.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan({"my.package.name.services", "my.package.name.mappers", "my.package.name.commands"})
public class MyConfig {
}
package my.package.name.commands;
import dev.alangomes.springspigot.context.Context;
import lombok.RequiredArgsConstructor;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;
@Command(
name = "myCommand",
mixinStandardHelpOptions = true,
description = "Some Command",
aliases = {"myCmd"}
)
@RequiredArgsConstructor
class MyCommand implements Runnable
@Parameters(
index = "0",
description = "Some param",
paramLabel = "myParam"
)
private int myParam;
private final Context context;
@Override
public void run() {
context.getSender().sendMessage("Hello World!")
}
}
Let me know more about your idea. You mean a plugin that runs the main Spring context and have some "modules"? Like an API?
That was indeed the idea I can maybe create a mockup. I am already using a similar setup for HeadsPluginAPI, HeadsInventory and HeadSweeper, but it would be nice if there was an official plugin that did this, so that other devs don't have to hook into my plugin to use this functionality.