Thursday, September 28, 2023

Enable Java EE Annotations, Java 9 onwards

  • Java EE or Java, enterprise Edition is not available by default since Java 9.
  • To access Java EE we need to include following library in Java 9
    • javax.annotation-api
  • Since @ Postconstruct and @Predestroy annotation Are parts of Java EE. We need to use following tag in our beans xml To enable all Java EE beans.
    • <context:annotation-config />
  • However, we may not require to enable all Java EE annotations in some cases Which is also a good programming practice.In such cases To enable only a single bean and it’s corresponding annotation we must declare that class as a bean Explicit in our xml file.
    • For example to Enable @postconstruct and @predestroy annotations, we must Declare following bean explicitly
      • <bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>

No comments:

Post a Comment

Spring Boot

What is circular/cyclic dependency in spring boot? When two services are interdependent on each other, that is to start one service, we requ...