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

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

    I'm using Spring 2.0 M2
    I get SAXParseException during startup


    Here is my configuration

    <?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"
    xmlns:jndi="http://www.springframework.org/schema/jndi"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
    http://www.springframework.org/schema/jndi http://www.springframework.org/schema/jndi/spring-jndi.xsd">

    <!-- ========================= RESOURCE DEFINITIONS ========================= -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName}"/>
    <property name="url" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
    </bean>
    </beans>


    2006-08-30 15:19:43,691 INFO [org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization started
    2006-08-30 15:19:43,691 INFO [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/spring_appsWeb]] - Loading Spring root WebApplicationContext
    2006-08-30 15:19:43,862 INFO [org.springframework.beans.factory.xml.XmlBeanDefin itionReader] - Loading XML bean definitions from ServletContext resource [/WEB-INF/dataAccessContext-local.xml]
    2006-08-30 15:19:43,882 DEBUG [org.springframework.beans.factory.xml.XmlBeanDefin itionReader] - Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderFactoryImpl@15ac3c9]
    2006-08-30 15:19:43,882 DEBUG [org.springframework.beans.factory.xml.ResourceEnti tyResolver] - Attempting to resolve DTD [http://www.springframework.org/dtd/spring-beans.dtd] using [org.springframework.beans.factory.xml.BeansDtdReso lver].
    2006-08-30 15:19:43,882 DEBUG [org.springframework.beans.factory.xml.BeansDtdReso lver] - Trying to resolve XML entity with public ID [-//SPRING//DTD BEAN//EN] and system ID [http://www.springframework.org/dtd/spring-beans.dtd]
    2006-08-30 15:19:43,882 DEBUG [org.springframework.beans.factory.xml.BeansDtdReso lver] - Trying to locate [spring-beans.dtd] in Spring jar
    2006-08-30 15:19:43,892 DEBUG [org.springframework.beans.factory.xml.BeansDtdReso lver] - Found beans DTD [http://www.springframework.org/dtd/spring-beans.dtd] in classpath
    2006-08-30 15:19:43,932 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
    org.springframework.beans.factory.BeanDefinitionSt oreException: Line 10 in XML document from ServletContext resource [/WEB-INF/dataAccessContext-local.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Attribute "xmlns" must be declared for element type "beans".
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.error(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTD Validator.addDTDDefaultAttrsAndValidate(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTD Validator.handleStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTD Validator.startElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tScannerImpl$ContentDispatcher.scanRootElementHook (Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl$FragmentContentDispatcher.dis patch(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLPars er.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.DOMPars er.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderImpl.parse(Unknown Source)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:258)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:209)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:184)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:128)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:144)
    at org.springframework.web.context.support.XmlWebAppl icationContext.loadBeanDefinitions(XmlWebApplicati onContext.java:126)
    at org.springframework.web.context.support.XmlWebAppl icationContext.loadBeanDefinitions(XmlWebApplicati onContext.java:94)
    at org.springframework.context.support.AbstractRefres hableApplicationContext.refreshBeanFactory(Abstrac tRefreshableApplicationContext.java:89)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:279)
    at org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:155)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:240)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:178)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 49)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3729)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4187)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1013)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:718)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1013)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:442)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:450)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:709)
    at org.apache.catalina.startup.Catalina.start(Catalin a.java:551)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:294)
    at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:432)

  • #2
    Re: org.xml.sax.SAXParseException: Attribute &quot;xmlns&quot; must be declared for element typ

    I've run into a similar problem as some other people on the forum did and unfortunately I'm quite stuck on this issue right now. Apparently switching from Spring 1.x and plain vanilla dtd files to Spring 2.0 and xsd files is not such a simple thing as it should be and is causing us some trouble: the attribute xmlns is thought to no longer be a valid keyword.

    Any help would be greatly appreciated.

    I'm running Spring 2.0 + Hibernate 3.2. and in order to eliminate/minimize any versioning missmatch, I'm using jars only from the spring framework 2.0 dependency distribution dirs.

    Here is my stack trace and my appContext.xml file. The crash happens right at the beginning while first parsing the appContext file.

    Many thanks indeed,
    -Petre

    org.springframework.beans.factory.BeanDefinitionSt oreException: Line 14 in XML document from class path resource [cnwk/commerce/lass/financials/resources/conf/spring/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Attribute "xmlns" must be declared for element type "beans".
    Caused by: org.xml.sax.SAXParseException: Attribute "xmlns" must be declared for element type "beans".
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.createSAXParseException(ErrorHandlerWrap per.java:236)
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.error(ErrorHandlerWrapper.java:172)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(XMLErrorReporter.java:382)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(XMLErrorReporter.java:316)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTD Validator.addDTDDefaultAttrsAndValidate(XMLDTDVali dator.java:1306)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTD Validator.handleStartElement(XMLDTDValidator.java: 1971)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTD Validator.startElement(XMLDTDValidator.java:795)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanStartElement(XMLDocumentF ragmentScannerImpl.java:878)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tScannerImpl$ContentDispatcher.scanRootElementHook (XMLDocumentScannerImpl.java:1157)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl$FragmentContentDispatcher.dis patch(XMLDocumentFragmentScannerImpl.java:1794)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanDocument(XMLDocumentFragm entScannerImpl.java:368)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:834)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:764)
    at com.sun.org.apache.xerces.internal.parsers.XMLPars er.parse(XMLParser.java:148)
    at com.sun.org.apache.xerces.internal.parsers.DOMPars er.parse(DOMParser.java:250)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderImpl.parse(DocumentBuilderImpl.java:292)
    at org.springframework.beans.factory.xml.DefaultDocum entLoader.loadDocument(DefaultDocumentLoader.java: 77)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:405)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:357)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:334)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:126)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:142)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:168)
    at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:113)
    at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:79)
    at org.springframework.context.support.AbstractRefres hableApplicationContext.refreshBeanFactory(Abstrac tRefreshableApplicationContext.java:94)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:294)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:92)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:77)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:68)
    at cnwk.commerce.lass.financials.HibernateBaseTestCas e.setUp(HibernateBaseTestCase.java:38)
    at cnwk.commerce.lass.financials.HibTest.setUp(HibTes t.java:18)
    at junit.framework.TestCase.runBare(TestCase.java:125 )
    at junit.framework.TestResult$1.protect(TestResult.ja va:106)
    at junit.framework.TestResult.runProtected(TestResult .java:124)
    at junit.framework.TestResult.run(TestResult.java:109 )
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:2 08)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at junit.textui.TestRunner.doRun(TestRunner.java:116)
    at com.intellij.rt.execution.junit2.IdeaJUnitAgent.do Run(IdeaJUnitAgent.java:58)
    at junit.textui.TestRunner.start(TestRunner.java:172)
    at com.intellij.rt.execution.junit.TextTestRunner2.st artRunnerWithArgs(TextTestRunner2.java:23)
    at com.intellij.rt.execution.junit2.JUnitStarter.prep areStreamsAndStart(JUnitStarter.java:98)
    at com.intellij.rt.execution.junit2.JUnitStarter.main (JUnitStarter.java:32)

    ---------------------
    appContext.xml:
    ---------------------

    <?xml version="1.0" encoding="UTF-8"?>
    <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/schem...-beans-2.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schem...ing-tx-2.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

    <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalEntityMana gerFactoryBean">
    <!--
    <property name="jpaProperties">
    <props>
    <prop key="show_sql">true</prop>
    </props>
    </property>
    -->
    <!-- inject a HibernateJpaVendorAdapter -->
    <property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
    <property name="database" value="MYSQL" />
    <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
    <property name="showSql" value="true" />
    <property name="generateDdl" value="true" />
    </bean>
    </property>

    <!-- The persistence unit is autodetected because it exists at the location specified by the spec 'META-INF/persistence.xml'. -->
    <!--<property name="persistenceUnitName" value="LassFinancialsEntityMgr" />-->
    </bean>

    <!-- Begin Transaction Handling -->

    <bean id="transactionManager"
    class="org.springframework.orm.jpa.JpaTransactionM anager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <bean class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor"/>

    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="do*" propagation="REQUIRED"/>
    <tx:method name="delete*" propagation="REQUIRED"/>
    <tx:method name="*" propagation="SUPPORTS" read-only="true"/>
    </tx:attributes>
    </tx:advice>

    </tx:advice>

    <aop:config>
    <aopointcut id="transactionalDaoMethods"
    expression="execution(* cnwk.commerce.lass.financials.api.dao.*Dao.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="transactionalDaoMethods"/>
    </aop:config>

    <bean id="baseDao" class="cnwk.commerce.lass.financials.hibernate.dao .BaseDaoJpa"/>
    <bean id="batchQueriesDao" class="cnwk.commerce.lass.financials.hibernate.dao .BatchQueriesDaoJpa"/>
    <bean id="advancedQueriesDao" class="cnwk.commerce.lass.financials.hibernate.dao .AdvancedQueriesDaoJpa"/>

    <!-- End Transaction Handling-->

    </beans>

    -----------------

    Comment


    • #3
      Hari,

      You have the old dtd mixed with the new schema (I only use dtd or schema, not both). Try using only one (and if you use dtd, you need to use the new one.

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

      Comment


      • #4
        Re: Attribute &quot;xmlns&quot; must be declared for element typ

        Thanks mjs6300 for your prompt response. Actually, in my case, I had an early version of my appContext.xml file that was indeed mixing some dtd and xsd doctype references lingering in my classpath, blindfolding the right version that I posted earlier and which was supposed to work. Pretty silly. That was it. Once I've removed the bad file, my code started working just fine.

        Comment


        • #5
          I am trying to use Java 5 and spring-framework-2.5.4 and experience similar problem.

          Part of my configuration file is:

          <?xml version="1.0" encoding="UTF-8"?>
          <!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" >

          I am getting exception:
          nested exception is org.xml.sax.SAXParseException: Attribute "xmlns" must be declared for element type "beans".


          I have read numerous posts related to this subject, but nothing worked so far. An advice would be highly appreciated.

          Comment

          Working...
          X