[jboss-user] [JBoss AOP] - Re: Can't read parameter annotations through reflection
dwl8
do-not-reply at jboss.com
Mon Dec 4 22:10:06 EST 2006
Thank you both for your replies.
flavia, all my annotations are set to RetentionPolicy.RUNTIME. If only that was the issue... :)
stalep, I created a unit test and it read the annotation correctly. It seems that when I deploy it to my app server (Tomcat) the annotation can't be read. Here's a simple class I was using to recreate the issue.
| public class Person {
| private static HashMap<Integer,Person> peopleMap = new HashMap<Integer,Person>();
|
| @ReadLock
| public static Person getPerson(@FirmId Integer firmId) {
| try {
| Method m = Person.class.getMethod("getPerson",Integer.class);
| Annotation[][] paramAnnot = m.getParameterAnnotations();
| for(Annotation[] a : paramAnnot) {
| System.out.println("# of Annotations Found: " + a.length);
| //log.debug("# of Annotations Found: " + a.length);
| }
| } catch(NoSuchMethodException e) {
| System.out.println("Method not found");
| //log.debug("No Such Method");
| }
| return peopleMap.get(firmId);
| }
|
| public static void main(String[] args) {
| try {
| Method m = Person.class.getMethod("getPerson",Integer.class);
| Annotation[][] paramAnnot = m.getParameterAnnotations();
| for(Annotation[] a : paramAnnot) {
| System.out.println("# of Annotations Found: " + a.length);
| //log.debug("# of Annotations Found: " + a.length);
| }
| } catch(NoSuchMethodException e) {
| System.out.println("Method not found");
| //log.debug("No Such Method");
| }
| }
| }
|
when main is run, i get "# of Annotations Found: 1". However, when I make a call to getPerson after it's been deployed to Tomcat, I get "# of Annotations Found: 0". Strange.
Could anyone give this code a whirl and keep me from losing my sanity?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3991174#3991174
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3991174
More information about the jboss-user
mailing list