0

Have looked around a lot but am unable to figure out an approach or if it is even possible; here is the question, any directions/word of advice would be very helpful.

Is it possible to have a method annotation say, @TestAnnotation that could be used as follows?

@TestAnnotation(element="something" id="someId")
public void someMethod() {
    AnObj anObj = id.getAnObj();
} 

"someId" is a wrapper around "AnObj" class; 'id' is an instance of "someId". And whatever is passed to 'element' is to be accepted as a parameter or configuration element to be used in creating an instance of "someId" and assigning it to 'id'.

Thanks and regards

Qadir Hussain
  • 1,263
  • 1
  • 10
  • 26
5122014009
  • 3,766
  • 6
  • 24
  • 34

2 Answers2

1

And Why dont simple use AOP and do all that you need in @Before method

http://www.journaldev.com/2583/spring-aop-example-tutorial-aspect-advice-pointcut-joinpoint-annotations-xml-configuration
paul
  • 12,873
  • 23
  • 91
  • 153
1

Change it to this:

@TestAnnotation(element="something" id="someId")
public void someMethod(Object something, AnObj anObj) {

} 

Then you can set up an aspect to intercept methods with that annotation and assign the necessary objects to the parameters of the method before calling.

cowls
  • 24,013
  • 8
  • 48
  • 78
  • Thanks @cowls; will try it out. But in such an approach 'id' in @TestAnnotation would not really be of any significance, right? So please correct me if am missing something but looks like i cannot make it work, the way i imagined it to be. – 5122014009 Oct 07 '14 at 08:37
  • @Sayury Perhaps the value of the id could be used to look up AnObj in the aspect and assign it to the paramerer? ie, you could run this in the aspect: `AnObj anObj = id.getAnObj();` – cowls Oct 07 '14 at 08:39