Announcement Announcement Module
Collapse
No announcement yet.
Schemas, Eclipse Content assist and SAX Parse Exceptions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Schemas, Eclipse Content assist and SAX Parse Exceptions

    If I want a (not connected to the Internet copy of) Eclipse to provide me with content assistance when coding application contexts that reference Spring 2 schema tags (e.g. aop:aspect), the approach is apparently to lop out the xsi:schemaLocation tags from the context file, and add in the appropriate schemas into the XML catalog.

    This works fine as far as content assist goes, unless I have a custom schema (i.e. not one provided by Spring), in which case the content assist does not work at all, despite putting my custom xsd in the Eclipse XML catalog(ue).

    However, if I then run a test case that attempts to load the (xsi:schemaLocation-less) context file, I get an error. It works if I put back in the xsi:schemaLocation but then I get no content assist again.

    Any ideas ?

    Code:
    <?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"
    	
    	>
    
    	<bean id="validator" class="targetgroup.validator.jni.TgtAdr" />
    
    	<aop:config>
    	
    		
    		
    		<aop:pointcut id="validatorPointCut"  expression="execution(* targetgroup.validator.jni.TgtAdr.callValidator*(targetgroup.validator.jni.Taistr, ..)) and args(pI,..)"/>
    		<aop:aspect id="validatorAspect" ref="logger">
    
    			<aop:before
    				pointcut-ref="validatorPointCut"
    				method="log" />
    
    		</aop:aspect>
    	</aop:config>
    
    	<bean id="logger" class="test.ValidatorLogger" />
    </beans>
    
    org.springframework.beans.factory.BeanDefinitionStoreException: Line 6 in XML document from class path resource [test/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
    Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:172)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:382)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1944)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:330)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:779)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1794)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
    	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
    	at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:250)
    	at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
    	at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:77)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:405)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:357)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:126)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:168)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:94)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:294)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:138)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:125)
    	at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:104)
    	at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:75)
    	at junit.framework.TestCase.runBare(TestCase.java:125)
    	at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
    	at junit.framework.TestResult$1.protect(TestResult.java: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:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

  • #2
    Putting this at the top of my Spring beans XML files seems to work:

    <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/aop
    http://www.springframework.org/schem...ng-aop-2.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schem...ing-tx-2.0.xsd ">

    Comment


    • #3
      Originally posted by blidgey View Post
      Putting this at the top of my Spring beans XML files seems to work:

      <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/aop
      http://www.springframework.org/schem...ng-aop-2.0.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schem...ing-tx-2.0.xsd ">
      Ta. A lot of my schema locations were missing the 2.0 at the end....

      Comment


      • #4
        I have such beans construction:

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

        .......

        <tx:advice id="txAdviceModificatorReqProcessor" transaction-manager="transactionManager">
        <tx:attributes>
        <tx:method name="create*" read-only="false" rollback-for="java.lang.Exception"/>
        <tx:method name="update*" read-only="false" rollback-for="java.lang.Exception"/>
        <tx:method name="drop*" read-only="false" rollback-for="java.lang.Exception"/>
        <tx:method name="grant*" read-only="false" rollback-for="java.lang.Exception"/>
        <tx:method name="revoke*" read-only="false" rollback-for="java.lang.Exception"/>
        <tx:method name="*" read-only="true" rollback-for="java.lang.Exception"/>
        </tx:attributes>
        </tx:advice>

        <tx:advice id="txAdviceModificatorDao" transaction-manager="transactionManager">
        <tx:attributes>
        <tx:method name="insert*" read-only="false" rollback-for="java.lang.Exception" propagation="REQUIRED"/>
        <tx:method name="update*" read-only="false" rollback-for="java.lang.Exception" propagation="REQUIRED"/>
        <tx:method name="delete*" read-only="false" rollback-for="java.lang.Exception" propagation="REQUIRED"/>
        <tx:method name="archive*" read-only="false" rollback-for="java.lang.Exception" propagation="REQUIRED"/>
        <tx:method name="*" read-only="true" rollback-for="java.lang.Exception"/>
        </tx:attributes>
        </tx:advice>

        <aop:config>
        <aopointcut id="requestProcessor" expression="execution(* com.peterservice.ntd.crm.dcs.editor.service.Modifi cationRequestProcessor2.*(..))"/>
        <aopointcut id="editRulesRaw" expression="execution(* com.peterservice.ntd.crm.dcs.editor.service.RulesD ao.*(..))"/>
        <aopointcut id="editSecurityRaw" expression="execution(* com.peterservice.ntd.crm.dcs.editor.service.Securi tyDao.*(..))"/>
        <aopointcut id="getDimension" expression="execution(* com.peterservice.ntd.crm.dcs.editor.service.Dimens ionHolder.*(..))"/>

        <aop:advisor advice-ref="txAdviceModificatorReqProcessor" pointcut-ref="requestProcessor" order="3"/>
        <aop:advisor advice-ref="txAdviceModificatorDao" pointcut-ref="editRulesRaw" order="2"/>
        <aop:advisor advice-ref="txAdviceModificatorDao" pointcut-ref="editSecurityRaw" order="1"/>
        <aop:advisor advice-ref="txAdviceModificatorDao" pointcut-ref="getDimension" order="1"/>

        <aop:aspect id="clearResultsAspect_" ref="clearResultsAspect" order="1">
        <aop:after method="clearResults"
        pointcut="execution(* com.peterservice.ntd.crm.dcs.editor.service.RulesD ao.deleteClassifyType(..))"
        />
        </aop:aspect>
        </aop:config>


        </beans>

        When running the application on Apache Tomcat 5.5.20 I have the exception:

        Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListe ner
        org.springframework.beans.factory.BeanDefinitionSt oreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionSt oreException: Line 145 in XML document from ServletContext resource [/WEB-INF/beans/editor.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute 'order' is not allowed to appear in element 'aop:aspect'.
        Caused by:
        org.springframework.beans.factory.BeanDefinitionSt oreException: Line 145 in XML document from ServletContext resource [/WEB-INF/beans/editor.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute 'order' is not allowed to appear in element 'aop:aspect'.
        Caused by:
        org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute 'order' is not allowed to appear in element 'aop:aspect'.

        I've read the schema spring-aop-2.0.xsd and there attribute 'order' is allowed for element 'aspect'.

        Had anyone resolved such problem?

        Comment

        Working...
        X