@Override public void advise(MethodInvocation invocation) { String className = (String) invocation.getParameter(0); final Class<?> replacement = componentReplacer.getReplacement(className); if (replacement != null) { invocation.setParameter(0, replacement.getName()); } invocation.proceed(); } };
public void advise(MethodInvocation invocation) { Class<?>[] parameterTypes = invocation.getMethod().getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { if (parameterTypes[i].equals(String.class)) { String value = (String) invocation.getParameter(i); invocation.setParameter(i, reverse(value)); } } invocation.proceed(); if (invocation.getMethod().getReturnType().equals(String.class)) { if (invocation.didThrowCheckedException()) { Exception thrown = invocation.getCheckedException(Exception.class); invocation.setReturnValue(String.format("Invocation of method %s() failed with %s.", invocation.getMethod().getName(), thrown.getClass().getName())); return; } String value = (String) invocation.getReturnValue(); invocation.setReturnValue(reverse(value)); } }