Ste*_*yts 6 java spring spring-integration java-8 default-method
我想@ServiceActivator在Java 8默认接口方法上使用注释.此默认方法将根据业务规则委托此接口的另一个方法.
public interface MyServiceInterface {
@ServiceActivator
public default void onMessageReceived(MyPayload payload) {
if(payload.getAction() == MyServiceAction.MY_METHOD) {
...
myMethod(...);
}
}
public void myMethod(...);
}
Run Code Online (Sandbox Code Playgroud)
然后,此接口由Spring @Service类实现:
@Service
public class MyService implements MyServiceInterface {
public void myMethod(...) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
执行代码时,这不起作用!
我只能让它@ServiceActivator从默认方法中删除注释,并覆盖我的@Service类中的默认方法并委托给super方法:
@Service
public class MyWorkingService implements MyServiceInterface {
@ServiceActivator
@Override
public void onMessageReceived(MyPayload payload) {
MyServiceInterface.super.onMessageReceived(payload);
}
public void myMethod(...) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
覆盖默认方法会忽略默认方法的用途.
是否有其他方式以干净的方式实现此方案?