Monday, June 11, 2012

MYSQL - Special Character persisted for hyphon - Solution

Root cause of persisting/displaying of special character is Characterset of MYSQL database.

Execute below query in DB, check the  character set values. Character set client need to be in UTF8 format.

If it is working in testing db and not working in production db, then you can compare the result by running below sql query iin both the db and compare it. Comparing result can be applied in production db from testing db.

"SHOW VARIABLES LIKE 'character_set%';"

Tuesday, June 5, 2012

Solution for Spring circular reference

In Spring injection we may come acros circular reference exception.

Example for circular reference:
 <bean id="lookupService " class="com.AddressLookupServiceImpl">  
     <property name="xyzService" ref="xyzService" />  
   </bean>  
   <bean id="xyzService" class="com.XYZServiceImpl">  
     <property name="xyzService" ref="xyzService" />  
   </bean>    


  Here bean lookupService is referring to bean xyzService. Again bean xyzServiceis referring to lookupService. This is called circular reference.

To avoid circular reference issue, instead of having reference in child to parent we can just have the reference in parent bean alone as given below    

 <bean id="lookupService " class="com.AddressLookupServiceImpl">  
     <property name="xyzService" ref="xyzService" />  
   </bean>  
   <bean id="xyzService" class="com.XYZServiceImpl">  
   </bean>    

 Error creating bean with name 'XYZ': Bean with name 'XYZ' has been injected into other beans [XYZHelper, AHelper] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.

Solution for NoSuchMethodError

Sometime we face NoSuchMethodError exception in production environment. One of the root cause of this exception is same class exist in two different jar. But particular method is not present in the loaded class.

Lets explain with an example below exception says method readWSDL is not available in WSDLReader class.
In my project  WSDLReader class was available in two different jars namely axis-wsdl4j-1.5.1.jar and wsdl4j-1.6.2.jar. WSDLReaderinside axis jar doesn't have the method readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;). So we can exclude axis jar from pom and use only wsdl4j-1.6.2.jar.

Exception:
java.lang.NoSuchMethodError: javax.wsdl.xml.WSDLReader.readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;)Ljavax/wsdl/Definition;

POM changes:

 <dependency>  
       <groupId>com.ExampleService</groupId>  
       <artifactId>service</artifactId>  
         <exclusions>  
            <exclusion>  
             <artifactId>axis-wsdl4j</artifactId>  
             <groupId>axis</groupId>  
           </exclusion>  
         </exclusions>  
   </dependency  
               
   dependency>