samedi 7 mars 2015

How to keep Method Parameters Names with Spring Aspect in Java 8

I've done what's necessary to get the parameters name in Java 8. When MyBean has no aspect on it, i get the names: 'first' and 'second'.


But when the aspect is set the bean is marked as MyBean$$EnhancerBySpringCGLIB and all i have is : 'arg0' 'arg1'


This test has been made using spring 4.1.5 and aspectj 1.8.5.


What am i missing ?



package com.test;

public class MyBean {

public void doSomething(String first, int second) {
System.out.println("something");
}
}


package com.test;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class MinimalAspect {
@Around("execution(* com.test.MyBean.*(..))")
public void logAround(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("Around before is running!");
joinPoint.proceed();
System.out.println("Around after is running!");
}
}

package com.test;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
public static void main(String[] args) throws Exception {
ApplicationContext appContext = new ClassPathXmlApplicationContext("spring-config.xml");
MyBean myBean = (MyBean) appContext.getBean("myBean");
for (Method method : myBean.getClass().getMethods()) {
System.out.print(method.getName() + "(");
for (Parameter parameter : method.getParameters()) {
System.out.print(parameter.getType());
System.out.print(' ');
System.out.print(parameter.getName());
System.out.print(' ');
}
System.out.println(")");
}
}
}


<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:aop="http://ift.tt/OpNdV1"
xmlns:context="http://ift.tt/GArMu7"
xsi:schemaLocation="http://ift.tt/GArMu6
http://ift.tt/1cnl1uo
http://ift.tt/OpNdV1
http://ift.tt/1eQJ7vy ">

<aop:aspectj-autoproxy />
<bean id="myBean" class="com.test.MyBean" />
<!-- Aspect -->
<bean id="minimalAspect" class="com.test.MinimalAspect" />
</beans>

Aucun commentaire:

Enregistrer un commentaire