codestyle; put javadoc before or after annotation?

I know that it isn’t the most vital of issues, but I just realised that I can put the javadoc comment block before or after the annotation. What would we want to adopt as a coding standard? /** * This is a javadoc comment before the annotation */ @Component public class MyClass { @Autowired /** … Read more

intellij incorrectly saying no beans of type found for autowired repository

I have created a simple unit test but IntelliJ is incorrectly highlighting it red. marking it as an error No beans? As you can see below it passes the test? So it must be Autowired? 43 Answers 43 I had this same issue when creating a Spring Boot application using their @SpringBootApplication annotation. This annotation … Read more

Why is it not possible to extend annotations in Java?

I don’t understand why there is no inheritance in Java annotations, just as Java classes. I think it would be very useful. For example: I want to know if a given annotation is a validator. With inheritance, I could reflexively navigate through superclasses to know if this annotation extends a ValidatorAnnotation. Otherwise, how can I … Read more

Does Spring @Transactional attribute work on a private method?

If I have a @Transactional -annotation on a private method in a Spring bean, does the annotation have any effect? If the @Transactional annotation is on a public method, it works and open a transaction. public class Bean { public void doStuff() { doPrivateStuff(); } @Transactional private void doPrivateStuff() { } } … Bean bean … Read more

Which types can be used for Java annotation members?

Today I wanted to create my first annotation interface following this documentation and I got this compiler error Invalid type for annotation member”: public @interface MyAnnotation { Object myParameter; ^^^^^^ } Obviously Object cannot be used as type of an annotation member. Unfortunately I could not find any information on which types can be used … Read more