Thursday, May 8, 2014

cvc-complex-type.2.3: Element 'beans:bean' cannot have character [children], because the type's content type is element-only.


cvc-complex-type.2.3: Element 'beans:bean' cannot have character [children], because the type's content type is element-only.

Problem :


We come across this common exception when using any xml configuration files, infact any xml file with namespace.

Exception I Encountered Was :


###################################################################################################################

cvc-complex-type.2.3: Element 'beans:bean' cannot have character [children], because the type's content type is element-only.

###################################################################################################################

Solution :


This exception was caused when i was trying to copy paste a default configuration for my security-app-context.xml file for my Spring Security cofiguration file. Mistakingly i had copied an extra closing tag. Please refer below to see how i fixed it.

Example :


- Follow the below steps outlined and you should be able to resolve it :

1)Try to open the xml in Iexplorer or any xml view tool and see whether the xml is rendered properly. 2) Or you can do a ctrl + shift + F to format the xml file and see if xml is welformed or not. 3)With the above step you should be able to find the exact location where you need to make changes to make the xml welformed. 4)In my case i had to just remove the extra "<" closing tag to resolve the issue. I hope this resolves your above exception, happy coding.


Similar Exception :

     

- cvc-complex-type.2.3: Element 'beans:bean' cannot have character [children], because the type's content type is element-only.
- cvc-complex-type.2.3:Element 'beans' cannot have character [children] type's content type is element
- Element 'beans' cannot have character [children], because the type's content type is