简体   繁体   English

弹簧注入和注解

[英]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,它可以按以下方式使用?

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

"someId" is a wrapper around "AnObj" class; "someId""AnObj"类的包装; 'id' is an instance of "someId" . 'id'"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' . 传递给'element'任何'element'都将被接受为参数或配置元素,用于创建"someId"的实例并将其分配给'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. 然后,您可以设置一个方面来拦截带有该批注的方法,并在调用之前将必要的对象分配给方法的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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