I would like to use the @ServiceActivator annotation for the default Java 8 interface method. This method will by default delegate another method of this interface depending on business rules.
public interface MyServiceInterface { @ServiceActivator public default void onMessageReceived(MyPayload payload) { if(payload.getAction() == MyServiceAction.MY_METHOD) { ... myMethod(...); } } public void myMethod(...); }
This interface is then implemented by the Spring @Service class:
@Service public class MyService implements MyServiceInterface { public void myMethod(...) { ... } }
When executing the code, this does not work!
I can get it working to remove the @ServiceActivator annotation from the default method and override this default method in my @Service class and delegate the super method:
@Service public class MyWorkingService implements MyServiceInterface { @ServiceActivator @Override public void onMessageReceived(MyPayload payload) { MyServiceInterface.super.onMessageReceived(payload); } public void myMethod(...) { ... } }
Overriding the default method ignores the default method assignment.
Is there any other way to implement this scenario in its purest form?
source share