Questions tagged [java-annotations]

211 questions
1
vote
1 answer

custom annotations to modify values

I need your support and thanks for your Java/Annotations support.. I would to create a custom annotation f.e. @ModifyRegex to annotatate variables and my approach is to modify/replace parts of the value of the annotated…
oyloom
  • 13
  • 3
1
vote
2 answers

In Spring Boot AOP, how to get class annotation when in the method "Around" period?

Thanks for all the friends here. I know how to get the annotation parameter for the annotation set on method. While I would like to add the annotation in the Class level. How to retrieve the attribute from Class in the AOP Around method? By the way,…
tony
  • 91
  • 1
  • 8
1
vote
2 answers

Take method argument as an argument in the annotation in Java 8

I have looked up and till now it doesn't seem possible, so, if that's the case, what is the best alternative to meet the following requirement? @Authentication_Annotation(id, password) public void method(String id, String password, String param) { …
Bugs Buggy
  • 1,514
  • 19
  • 39
1
vote
1 answer

Is it possible to apply manually instantiated Java annotations on method parameters?

In the following topics: How to create an instance of an annotation Create Annotation instance with defaults, in Java it is discussed how to create an instance of a Java annotation. My question is: having such an annotation instance, what can I do…
kdr
  • 93
  • 8
1
vote
1 answer

Junit5 and Maven: @BeforeAll initialization method not being called

I would appreciate any hints as to why @BeforeAll is skipped in the following Junit5 test suite. FYI, my output when I build with Maven: ------------------------------------------------------- T E S T…
benthumb
  • 35
  • 4
1
vote
1 answer

Mockito erases annotations applied to my class

I have an annotation, @Retention(RetentionPolicy.RUNTIME) @Target(value={ElementType.METHOD, ElementType.TYPE}) public @interface JobLoggable { JobType jobType(); JobDomain domain(); JobStatus jobInitialStatus(); } which I apply to my…
Calicoder
  • 1,322
  • 1
  • 19
  • 37
1
vote
1 answer

Java Annotation Processor getEnclosingElement() method

Hello,I would like to ask what is the meaning of the comments of the getEnclosingElement() method in the Element interface, I do not quite understand. javadoc as follows: Returns the innermost element within which this element is, loosely…
Liu Silong
  • 4,902
  • 3
  • 19
  • 28
1
vote
1 answer

Custom annotation not working for nested object field

I have created small custom annotation which is for validation. If the field is annotated with custom annotation, it will throw the exception. Below is the code import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import…
Vaibs
  • 1,546
  • 9
  • 31
1
vote
1 answer

is there any way of replace this code of this way?

I' am trying to replace this code: public void doThing(){ if(User.getInstance().isLoggin()){ ..... } } by this @withUser public void doThing(){ .... } I saw about the interceptors and annotation, but I cannot do it. Is this…
Tlaloc-ES
  • 4,825
  • 7
  • 38
  • 84
1
vote
2 answers

How to get class that annotation applied to in Java Annotation Processor?

I wrote a custom Java Annotation Processor that if applied to a class, generates a class with name of annotated class fields. While executing, I can find name of annotated class (like "com.package.Person") with…
Homayoun Behzadian
  • 1,053
  • 9
  • 26
1
vote
0 answers

How to retrieve javax.lang.model.type.TypeMirror of com.sun.source.tree.*TypeTree?

I wanted to analyse a method body during compilation time and potentially introduce a minor modification to it. I have used com.sun.source.util.Trees.getTree(ExecutableElement) and TreeVisitor. Unfortunately, TreeVisitor.visit*Type(...) methods…
AndyB
  • 490
  • 1
  • 4
  • 7
1
vote
2 answers

Logging elapsed time of execution in SpringBoot rest API

It could be a simple solution but I am unable to get it done. I need to log the overall execution time for my request in SpringBoot Rest API. Request always enters to MainController always and can exit from two places- Main Restcontroller same…
Avhi
  • 806
  • 2
  • 15
  • 29
1
vote
2 answers

Custom Filter for Springs ApplicationEvents

In Spring, when I write an EventHandler, I can set a conditon, to filter out uninteresting events, like this: // I use lombok public class TopicEvent extends ApplicationEvent { @Getter @Setter private String topic; @Getter @Setter private…
1
vote
1 answer

Configure .jar to expose its dependencies

I have 3 modules: annotations, annotation_processor and app. annotations/build.gradle apply plugin: 'java-library' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) } annotation_processor/build.gradle apply plugin:…
Abbas
  • 3,529
  • 5
  • 36
  • 64
1
vote
0 answers

Cannot call value method of Annotation

I have this: public class Bootstrapper { public static List> annots = Arrays.asList( NotNull.class, ColumnType.class, RuntimeType.class, DefaultValue.class ); } and then this is called in a static…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817