Spring Support
It is possible integrate brainslug with the Spring application context, so that the Spring Beans are available in the execution context.
Setup
Just import the spring configuration class into you application context.
Calls to the ExecutionContext
or the Registry
will then return the beans from the Spring application context:
@Configuration
@Import(brainslug.spring.SpringBrainslugConfiguration.class)
public class ConfigurationExample {
@Component
public static class SpringExampleTask implements Task {
Environment environment;
@Autowired
public SpringExampleTask(Environment environment) {
this.environment = environment;
}
@Override
public void execute(ExecutionContext context) {
printHello(context.property("name", String.class));
context.service(SpringExampleTask.class).printHello("again");
}
public void printHello(String name) {
System.out.println(
format("Hello %s!", name)
);
}
}
@Bean
FlowBuilder flowBuilder() {
return new FlowBuilder() {
@Override
public void define() {
flowId(id("spring-flow"));
start(task(id("spring-task")).delegate(SpringExampleTask.class));
}
};
}
public static void main(String[] args) {
AnnotationConfigApplicationContext applicationContext =
new AnnotationConfigApplicationContext(ConfigurationExample.class);
BrainslugContext brainslugContext = applicationContext.getBean(BrainslugContext.class);
brainslugContext.startFlow(FlowBuilder.id("spring-flow"),
newProperties().with("name", "World"));
}
}
Will output the two lines:
Hello World!
Hello again!