简体   繁体   中英

Spring Injection and Annotations

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

为什么不简单地使用AOP并在@Before方法中完成所有您需要的工作

http://www.journaldev.com/2583/spring-aop-example-tutorial-aspect-advice-pointcut-joinpoint-annotations-xml-configuration

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM