Skip to content
Advertisement

Tag: annotations

How @Target(ElementType.ANNOTATION_TYPE) works

Java annotations are marked with a @Target annotation to declare possible joinpoints which can be decorated by that annotation. Values TYPE, FIELD, METHOD, etc. of the ElementType enum are clear and simply understandable. Question WHY to use @Target(ANNOTATION_TYPE) value? What are the annotated annotations good for? What is their contribution? Give me an explanation of an idea how it works

How to disable @PostConstruct in Spring during Test

Within a Spring Component I have a @PostConstruct statement. Similar to below: During Unit tests I would not like to have the @PostConstruct function called, is there a way to telling Spring not to do post processing? Or is there a better Annotation for calling a initiation method on a class durning non-testing ? Answer Since you are not testing

Passing annotation properties to meta-annotations

Say I have an annotation with a property: and I want to create a compound annotation with several meta-annotations, including the one that takes a property Is there a way that I can pass properties to the compound annotation to one of the meta annotations? Eg, something like this: that is equivalent to, but much more convenient than Thanks! PS

An alternative to @Value annotation in static function

It’s not possible to use @Value on a static variable. When I do this, 0 is printed. So what is a good alternative to this? Answer Spring inject noting in static field (by default). So you have two alternatives: (the better one) make the field non static (the ugly hack) add an none static setter which writes in the static

Default properties of Java Annotation

What are the exact default values of two meta annotations (Target and Retention) in a user defined annotation? Answer According to the source code, none of them has a default value, which means you must provide it, whenever you use the annotation. The meaning of the missing annotation is defined in the javadoc: For Target it means If a Target

Advertisement