Custom Search

Friday, June 28, 2013

is invalid; nested exception is org.xml.sax.SAXParseException: Element type "bean" must be followed by either attribute specifications, ">" or "/>".

If you are getting extra special characters (like ascii or hexa or any weird characters) in your script/xml/txt file OR
If you are getting an error like below in your logs:

2013-06-28 08:57:02,295 ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed>

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 67 in XML document from ServletContext resource [/WEB-INF/spring-configuration/ticketRegistry.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Element type "bean" must be followed by either attribute specifications, ">" or "/>".

        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(

        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(

        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(









        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(

        at org.springframework.web.context.ContextLoader.initWebApplicationContext(

        at org.springframework.web.context.ContextLoaderListener.contextInitialized(

        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized_aroundBody0(

        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized_aroundBody1$advice(

        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized(

        at org.apache.catalina.core.StandardContext.listenerStart(

        at org.apache.catalina.core.StandardContext.start(

        at org.apache.catalina.core.ContainerBase.addChildInternal(

        at org.apache.catalina.core.ContainerBase.addChild(

        at org.apache.catalina.core.StandardHost.addChild(

        at org.apache.catalina.startup.HostConfig.deployWAR(

        at org.apache.catalina.startup.HostConfig.deployWARs(

        at org.apache.catalina.startup.HostConfig.deployApps(

        at org.apache.catalina.startup.HostConfig.start(

        at org.apache.catalina.startup.HostConfig.lifecycleEvent(

        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(

        at org.apache.catalina.core.ContainerBase.start(

        at org.apache.catalina.core.StandardHost.start(

        at org.apache.catalina.core.ContainerBase.start(

        at org.apache.catalina.core.StandardEngine.start(

        at org.apache.catalina.core.StandardService.start(

        at org.apache.catalina.core.StandardServer.start(

        at org.apache.catalina.startup.Catalina.start(

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(

        at java.lang.reflect.Method.invoke(

        at org.apache.catalina.startup.Bootstrap.start(

        at org.apache.catalina.startup.Bootstrap.main(

Caused by: org.xml.sax.SAXParseException: Element type "bean" must be followed by either attribute specifications, ">" or "/>".

The reason could be that your xml file contains some invisible characters to your eye (basically some ansi characters), Normally this happens when you copy the code from internet browser or pdf  and paste into your editor/IDE.

Though you keep formatting the xml, but still the error remains same as shown below:

Solutions #1:
1. Copy the code showing error into just plain notepad.
2. try deleting all the spaces between words and then manually use spacebar to add spaces between words/attributes.
3. Again copy the code from notepad and then paste into your IDE/Editor.

This should have solved.

But, in some cases, this also does not solve the issue.

Solutions #2:
1. Open the same excel file in an advanced editor like notepad++,
2. Go to the "Encode" menu --> choose "Encode in ANSI"

3. Now you should be able to see all those invisible ansi characters you have derived  while copy pasting  from internet (shown below):

4. So you got now proof that you have some to give company there in your xml file.
    Delete all those, characters manually or by using the editors find/replace (ctrl + h ) option:

5. Now try changing the encoding to the other formats, you will be surprised to see more invisible characters suddenly becomes visible to you :)

6. Play around with encodings, delete those chars and Save.
    Rerun the application. You should be fine.

If you are in Unix Environment, and you doubt your script file (.sh) contains any special characters, you can view those special characters using VI editor.

Open the file using VI editor:
$ vi <file_name>
Hit Esc
Then type in the command line of the vi editor as (To be able to see the extra characters)-  :set list 
To again hide the special characters or make the file to be seen as normal, type in the command line-  :set nolist 

No comments:

Post a Comment