Announcement Announcement Module
No announcement yet.
problem with "xmlns must be declared for element type beans" exception Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem with "xmlns must be declared for element type beans" exception

    Hi all,

    i'm a newbie here so pls. forgive my missteps. i tried to test a JMS POJO example but got this parse exception instead:

    Attribute "xmlns" must be declared for element type "beans".

    i am not sure what i'm missing here, but here is the file:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "">
    <beans xmlns=""

    <bean id="requestQueue" class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg value="PREADMIT.TO400.QUEUE"/>

    <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFacto ry">
    <property name="brokerURL" value="tcp://localhost:61616"/>

    <!-- this is the Message Driven POJO (MDP) -->
    <bean id="messageListener" class="com.hmacorpmis.msglistener.ActiveMQJMSListe ner"/>

    <!-- and this is the attendant message listener container -->
    <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMes sageListenerContainer">
    <property name="concurrentConsumers" value="5"/>
    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="destination" ref="requestQueue"/>
    <property name="messageListener" ref="messageListener"/>

    any help is greatly appreciated. thanks.

  • #2
    You are mixing the DTD and XSD declarations. Simply remove the line:
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "">
    ...and that should do the trick.


    • #3
      Hi Mark,

      appreciate the response. when i took out the DTD, it then came up with another msg:

      org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".

      Erwin Pader
      Health Management Associates, Inc.
      Naples, FL


      • #4
        btw, i am using jdk 1.5, and these are the following jars in cp:




        • #5
          finally worked! but i found it weird that i had to delete xmlns and schemalocation and replaced both with:

          <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "">

          there must be something in the schema that's causing the parser to go whacko.

          any explanations on this?


          • #6
            What version of Spring are you using - is it 2.0 final?


            • #7
              It sounds like the JAXP parser might be something like Crimson instead of Xerces. I'd check the specific release # of the JDK 1.5 installed, might need to be bumped up to one of the more recent update releases.


              • #8
                i am using spring 2.0 final

                regarding jdk 1.5, it looks like it's using xerces. i'll have to check again though if it's an old version.


                • #9
                  For Spring 2.0 final, you need to change the schema reference from "spring-beans.xsd" to "spring-beans-2.0.xsd".


                  • #10
                    Attribute &quot;xmlns&quot; must be declared for element type &quot;beans&quot;

                    I met with the same problem.I use spring1.2.8,the xml file is:
                    <?xml version="1.0" encoding="UTF-8"?>
                    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "">
                    <beans xmlns="">
                    <bean id="jmsTransport"
                    class="org.codehaus.xfire.transport.jms.JMSTranspo rt"
                    <constructor-arg ref="xfire"/>
                    <constructor-arg ref="connectionFactory"/>

                    <service xmlns:e="urn:Echo">
                    <implementationClass>org.codehaus.xfire.test.EchoI mpl</implementationClass>
                    <soap11Binding name="e:EchoJMSBinding" transport="urn:xfire:transport:jms">
                    <endpoint name="e:EchoJMSEndpoint" url="jms://Echo" />

                    <bean id="connectionFactory"
                    class="org.apache.activemq.ActiveMQConnectionFacto ry"
                    <constructor-arg value="vm://localhost?broker.persistent=false" type="java.lang.String"/>

                    The error information:
                    [thira-admin] ERROR [main] ContextLoader.initWebApplicationContext(211) | Context initialization failed
                    org.springframework.beans.factory.BeanDefinitionSt oreException: Line 3 in XML document from ServletContext resource [/WEB-INF/xFire-JmsService.xml] is
                    invalid; nested exception is org.xml.sax.SAXParseException: Attribute "xmlns" must be declared for element type "beans".
                    org.xml.sax.SAXParseException: Attribute "xmlns" must be declared for element type "beans".


                    • #11
                      Hello, I have run into the same issue as these other folks and I have not been able to find any additional information through searching the web or these forums. I looked in the spring documentation and it indicates you should be able to just switch to using the XSD declaration with no problem. I think that maybe in my case it is caused by the parser doing the wrong validation?? I tried removing the schema stuff and using a regular <beans> tag with the DTD, but then it can't recognize the tx:advice and other ones that use the schema. Please, I would like some clarification on this issue -- I need to get this working to move forward.

                      The error I receive is:

                      org.springframework.beans.factory.BeanDefinitionStoreException: Line 12 in XML d
                      ocument from ServletContext resource [/WEB-INF/applicationContext.xml] is invali
                      d; nested exception is org.xml.sax.SAXParseException: Document root element "bea
                      ns", must match DOCTYPE root "null".
                      org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE
                       root "null".
                              at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Un
                      known Source)
                              at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
                              at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
                              at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
                              at org.apache.xerces.impl.dtd.XMLDTDValidator.rootElementSpecified(Unkno
                      wn Source)
                              at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown
                              at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Sourc
                              at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElemen
                      t(Unknown Source)

                      Here are the contents of my applicationContext.xml:

                      <?xml version="1.0" encoding="UTF-8"?>
                      <!--!DOCTYPE beans SYSTEM "spring-beans-2.0.dtd">-->
                      <!--<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "C:\projects\xxxxxxxxx\war\WEB-INF\classes\spring-beans-2.0.dtd">-->
                      <!--<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "">-->
                      <beans xmlns=""
                             <!--       <beans>-->
                          <!-- HIBERNATE DATA SOURCE -->    
                          <bean id="hibernateDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
                      	    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
                      	    <property name="url" value="jdbc:oracle:thin:@localhost:1521:jregan"/>
                      	    <property name="username" value="xxxxxx"/>
                      	    <property name="password" value="xxxxxx"/>
                          <!-- HIBERNATE CONFIGURATION -->
                          <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                      	  <property name="mappingResources">
                      	  <property name="hibernateProperties">
                          <bean id="businessTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
                      	    <property name="dataSource">
                      		    <ref local="hibernateDataSource"/>
                          <!-- ================== DAOs ================== -->
                          <bean id="dao" class="xxxxxx.persistence.BaseHibernateDAO">
                              <property name="sessionFactory">
                              	<ref local="sessionFactory"/>
                          <!-- ================== Services ================== -->
                          <!-- this is the service object that we want to make transactional -->
                          <bean id="businessService" class="xxxxxxx.service.BusinessServiceImpl"/>
                          <!-- the transactional advice (i.e. what 'happens'; see the <aop:advisor/> bean below) -->
                          <tx:advice id="txAdvice" transaction-manager="businessTransactionManager">
                          	 <!-- the transactional semantics... -->
                      	    <!-- all methods starting with 'get' are read-only -->
                      	    <tx:method name="get*" read-only="true"/>
                      	    <!-- other methods use the default transaction settings (see below) -->
                      	    <tx:method name="*"/>
                          <!-- ensure that the above transactional advice runs for any execution of an operation defined by the FooService interface -->
                      	    <aop:pointcut id="businessServiceOperation" 
                      		    	  expression="execution(* xxxxxxxx.service.BusinessServiceImpl.*(..))"/>
                      	    <aop:advisor advice-ref="txAdvice" pointcut-ref="businessServiceOperation"/>
                          <!--to make entire service layer transactional -->
                      	    <aop:pointcut id="businessServiceMethods" expression="execution(* xxxxxxx.service.BusinessServiceImpl.*.*(..))"/>
                      	    <aop:advisor advice-ref="txAdvice" pointcut-ref="businesServiceMethods"/>
                          <bean id="businessService" class="xxxxxxxx.service.BusinessServiceImpl" singleton="false">
                              <property name="DAO">
                              	<ref local="dao"/>
                      	<property name="transactionManager">
                      		<ref local="businessTxManager"/>


                      • #12
                        hahaha ok ok I figured this out. The version of the spring.jar that was in our project (not added by me) was 1.x something. After putting in the 2.0 jars it worked -- however, I wish that spring would include the aspectj jars so I don't have to hunt them down. Hopefully this can help someone else.


                        • #13
                          I got burned by the same thing.

                          In my case it was because the MyEclipse 5.x Workbench bundles the spring-1.2.6.jar into the XFire lib when you "Add Webservice Capabilities" to a project. The best thing to do is define your own user library to replace the XFire lib. My new lib is called "XFireMinusSpring" and it has everything from C:\Program Files\MyEclipse Enterprise Workbench 5.1.0 GA\myeclipse\eclipse\plugins\com.genuitec.eclipse. ws.xfire_5.1.0\data\1.2\lib except for the stupid spring-1.2.6.jar.

                          Everything works fine now. So far...


                          • #14
                            One more thing...

                            I forgot to mention that you also have to replace the xbean-spring.jar that comes with the MyEclipse XFire package. You have to get xbean-spring-2.7.jar.


                            • #15
                              setting all the DTD's back to the following worked for me...

                              <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "">