Announcement Announcement Module
Collapse
No announcement yet.
problem with "xmlns must be declared for element type beans" exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

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

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

    <!-- 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"/>
    </bean>
    </beans>



    any help is greatly appreciated. thanks.

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

    Comment


    • #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

      Comment


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

        activemq-core-4.0.1.jar
        geronimo-jms_1.1_spec-1.0.jar
        geronimo-j2ee-management_1.0_spec-1.0.jar

        thanks.

        Comment


        • #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" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

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

          any explanations on this?

          Comment


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

            Comment


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

              Comment


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

                Comment


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

                  Comment


                  • #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" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
                    <beans xmlns="http://xfire.codehaus.org/config/1.0">
                    <xfire>
                    <transports>
                    <bean id="jmsTransport"
                    class="org.codehaus.xfire.transport.jms.JMSTranspo rt"
                    xmlns="http://xbean.org/schemas/spring/1.0">
                    <constructor-arg ref="xfire"/>
                    <constructor-arg ref="connectionFactory"/>
                    </bean>
                    </transports>
                    </xfire>

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

                    <bean id="connectionFactory"
                    class="org.apache.activemq.ActiveMQConnectionFacto ry"
                    singleton="true"
                    xmlns="http://xbean.org/schemas/spring/1.0/">
                    <constructor-arg value="vm://localhost?broker.persistent=false" type="java.lang.String"/>
                    </bean>
                    </beans>

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

                    Comment


                    • #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:

                      Code:
                      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
                       Source)
                              at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Sourc
                      e)
                              at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElemen
                      t(Unknown Source)

                      Here are the contents of my applicationContext.xml:


                      Code:
                      <?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" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">-->
                      <beans xmlns="http://www.springframework.org/schema/beans"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xmlns:aop="http://www.springframework.org/schema/aop"
                             xmlns:tx="http://www.springframework.org/schema/tx"
                             xsi:schemaLocation="
                             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
                             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
                             <!--       <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"/>
                          </bean>
                      
                          <!-- HIBERNATE CONFIGURATION -->
                          <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                      	  <property name="mappingResources">
                      		  <list>
                      			  <value>rank.hbm.xml</value>
                      			  <value>user.hbm.xml</value>
                      			  <value>person.hbm.xml</value>
                      			  <value>office.hbm.xml</value>
                      		  </list>
                      	  </property>
                      	  <property name="hibernateProperties">
                      		  <value>
                      		      hibernate.dialect=org.hibernate.dialect.OracleDialect
                      	          </value>
                      	  </property>
                          </bean>
                      
                          <bean id="businessTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
                      	    <property name="dataSource">
                      		    <ref local="hibernateDataSource"/>
                      	    </property>
                          </bean>
                      
                          <!-- ================== DAOs ================== -->
                          <bean id="dao" class="xxxxxx.persistence.BaseHibernateDAO">
                              <property name="sessionFactory">
                              	<ref local="sessionFactory"/>
                              </property>
                          </bean>
                          
                          <!-- ================== 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... -->
                         	 <tx:attributes>
                      	    <!-- 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="*"/>
                               </tx:attributes>
                          </tx:advice>
                        
                          <!-- ensure that the above transactional advice runs for any execution of an operation defined by the FooService interface -->
                          <aop:config>
                      	    <aop:pointcut id="businessServiceOperation" 
                      		    	  expression="execution(* xxxxxxxx.service.BusinessServiceImpl.*(..))"/>
                      	    <aop:advisor advice-ref="txAdvice" pointcut-ref="businessServiceOperation"/>
                          </aop:config>
                          <!--to make entire service layer transactional -->
                          <!--
                          <aop:config>
                      	    <aop:pointcut id="businessServiceMethods" expression="execution(* xxxxxxx.service.BusinessServiceImpl.*.*(..))"/>
                      	    <aop:advisor advice-ref="txAdvice" pointcut-ref="businesServiceMethods"/>
                          </aop:config>
                          -->
                      
                      
                          <!--
                          <bean id="businessService" class="xxxxxxxx.service.BusinessServiceImpl" singleton="false">
                              <property name="DAO">
                              	<ref local="dao"/>
                      	</property>
                      	<property name="transactionManager">
                      		<ref local="businessTxManager"/>
                      	</property>
                           </bean>
                           -->
                      </beans>

                      Comment


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

                        Comment


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

                          Comment


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

                            Comment


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

                              Code:
                              <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

                              Comment

                              Working...
                              X