Thursday, September 28, 2023

Create a bean of type java.util.properties

To create a bean of type java.util.properties in Java xml use the following code.


 <bean id="attendkey" class="java.util.Properties" name="attendenceKeys"/>  
 <bean id="attendkey.load" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">  
   <property name="targetObject"><ref bean="attendkey"/></property>  
   <property name="targetMethod"><value>putAll</value></property>  
   <property name="arguments">  
        <props>  
             <prop key="Present">1</prop>  
             <prop key="Absent" >-1</prop>  
       </props>  
  </property>  
 </bean>  

Example :

https://github.com/gauravmatta/springmvc/blob/master/book%20management%20system/src/main/java/com/springimplant/xml/config.xml

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"/>

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...