Package ratpack.core.service
Annotation Type DependsOn
-
@Documented @Retention(RUNTIME) @Target(TYPE) @Inherited public @interface DependsOn
Declares the other service types that services of the annotated type depend on.This annotation is only effective when present on
Service
types.import ratpack.core.server.ServerConfig; import ratpack.core.server.RatpackServer; import ratpack.core.service.DependsOn; import ratpack.core.service.Service; import ratpack.core.service.StartEvent; import ratpack.core.service.StopEvent; import java.util.ArrayList; import java.util.List; import static java.util.Arrays.asList; import static org.junit.jupiter.api.Assertions.assertEquals; public class Example { private static final List<String> EVENTS = new ArrayList<>(); private static class ServiceOne implements Service { @Override public void onStart(StartEvent event) throws Exception { EVENTS.add("one-start"); } @Override public void onStop(StopEvent event) throws Exception { EVENTS.add("one-stop"); } } @DependsOn(ServiceOne.class) private static class ServiceTwo implements Service { @Override public void onStart(StartEvent event) throws Exception { EVENTS.add("two-start"); } @Override public void onStop(StopEvent event) throws Exception { EVENTS.add("two-stop"); } } public static void main(String[] args) throws Exception { RatpackServer server = RatpackServer.of(s -> s .serverConfig(ServerConfig.embedded()) .registryOf(r -> r // note: order of registration is irrelevant here .add(new ServiceOne()) .add(new ServiceTwo()) ) ); server.start(); assertEquals(asList("one-start", "two-start"), EVENTS); server.stop(); assertEquals(asList("one-start", "two-start", "two-stop", "one-stop"), EVENTS); } }
- Since:
- 1.3
- See Also:
ServiceDependencies
-
-
Element Detail
-
value
Class<?>[] value
The types of services that services of the annotated type depend on.- Returns:
- the types of services that services of the annotated type depend on.
-
-