Announcement Announcement Module
Collapse
No announcement yet.
no declaration can be found for element 'tx:annotation-driven' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • no declaration can be found for element 'tx:annotation-driven'

    hi, i try to configure JSF+Spring+hibernate and i'm tying to run a test but when i use this "tx:annotation-driven" on my application-context.xml file,i get this error:

    The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'

    here is my application-context.xml
    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"
           xmlns:context="http://www.springframework.org/schema/context"
           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.5.xsd
              http://www.springframework.org/schema/aop 
              http://www.springframework.org/schema/aop/spring-aop-2.5.6.xsd
              http://www.springframework.org/schema/context 
              http://www.springframework.org/schema/context/spring-context-2.5.6.xsd
              http://www.springframework.org/schema/tx 
              http://www.springframework.org/schema/tx/spring-tx-2.5.6.xsd
    " xmlns:tool="http://www.springframework.org/schema/tool">
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
            <property name="url" value="jdbc:oracle:thin:@192.168.56.101:1521:Gpsi"/>
            <property name="username" value="omar"/>
            <property name="password" value="omar"/>
        </bean>
    
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
           <property name="dataSource" ref="dataSource"/>
           <property name="annotatedClasses">
                <list>
                    <value>om.mycompany.model.Course</value>
                    <value>om.mycompany.model.Student</value>
                    <value>om.mycompany.model.Teacher</value>
                </list>
           </property>
           <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
                </props>
           </property>
    
        </bean>
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
           <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
        <tx:annotation-driven transaction.manager="transactionManager"/>
    
        <context:annotation-config/>
        <context:component-scan base.package="com.mmycompany"/>
    </beans>
    and here is my CourseServiceImplTest still not implemented the tests:

    Code:
    public class CourseServiceImplTest {
    
        private static ClassPathXmlApplicationContext context;
        private static CourseService courseService;
        public CourseServiceImplTest() {
        }
    
        @BeforeClass
        public static void setUpClass() throws Exception {
            context=new ClassPathXmlApplicationContext("application-context.xml");
            courseService=(CourseService) context.getBean("courseService");
        }
    
        @AfterClass
        public static void tearDownClass() throws Exception {
            context.close();
        }
    
        @Before
        public void setUp() {
        }
    
        @After
        public void tearDown() {
        }
    
        /**
         * Test of getAllCourses method, of class CourseServiceImpl.
         */
        @Test
        public void testGetAllCourses() {
            System.out.println("getAllCourses");
            CourseServiceImpl instance = new CourseServiceImpl();
            List expResult = null;
            List result = instance.getAllCourses();
            assertEquals(expResult, result);
            // TODO review the generated test code and remove the default call to fail.
            fail("The test case is a prototype.");
        }
    
        /**
         * Test of getCourse method, of class CourseServiceImpl.
         */
        @Test
        public void testGetCourse() {
            System.out.println("getCourse");
            Integer id = null;
            CourseServiceImpl instance = new CourseServiceImpl();
            Course expResult = null;
            Course result = instance.getCourse(id);
            assertEquals(expResult, result);
            // TODO review the generated test code and remove the default call to fail.
            fail("The test case is a prototype.");
        }
    and here is the CourseServiceImpl:

    Code:
    @Service("courseService")
    @Transactional
    public class CourseServiceImpl implements CourseService{
    
        @Autowired
        private SessionFactory sessionFactory;
        @Override
        public List<Course> getAllCourses() {
            return sessionFactory.getCurrentSession().createQuery("from Course").list();    
        }
    
        @Override
        public Course getCourse(Integer id) {
            return (Course) sessionFactory.getCurrentSession().get(Course.class, id);
        }
    
        @Override
        public void save(Course course) {
           sessionFactory.getCurrentSession().saveOrUpdate(course);
        }
    
    }
    please any help is very apreciated thanks lot.

  • #2
    Can you paste the complete error stack trace.

    Comment


    • #3
      There is no property/attribute on tx:annotation-driven called transaction.manager it is transactionManager. Also I suggest using springs test context framework next to that your testcase is flawed because each method is creating a new instance of the CourseServiceImpl which will miserably let your testcase blow up with a nullpointer...

      Finally there is a tool namespace but it is nowhere to be found in your namespace declarations...

      Comment


      • #4
        hey thanks for your answers, i changed transaction.manager to transactionManager but still the same error, please i'm a newbi i don't know what i should do for the instance of the CourseServiceImpl should i put it the in constructor?

        Code:
         private static CourseService courseService;
         public CourseServiceImplTest() {
        courseService=(CourseService) context.getBean("courseService");
            }
        and also here is the complete error stack that you Kumara asked me:

        ATTENTION: Ignored XML validation warning
        org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/tx/spring-tx-2.5.6.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
        at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.createSAXParseException(ErrorHandlerWrap per.java:195)
        at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.warning(ErrorHandlerWrapper.java:96)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(XMLErrorReporter.java:380)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(XMLErrorReporter.java:318)
        at com.sun.org.apache.xerces.internal.impl.xs.travers ers.XSDHandler.reportSchemaErr(XSDHandler.java:254 1)
        at com.sun.org.apache.xerces.internal.impl.xs.travers ers.XSDHandler.reportSchemaWarning(XSDHandler.java :2532)
        at com.sun.org.apache.xerces.internal.impl.xs.travers ers.XSDHandler.getSchemaDocument(XSDHandler.java:1 836)
        at com.sun.org.apache.xerces.internal.impl.xs.travers ers.XSDHandler.parseSchema(XSDHandler.java:531)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maLoader.loadSchema(XMLSchemaLoader.java:552)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.findSchemaGrammar(XMLSchemaValidator.j ava:2437)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.handleStartElement(XMLSchemaValidator. java:1782)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.emptyElement(XMLSchemaValidator.java:7 25)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl.scanStartElement(XMLNSDocumentScann erImpl.java:377)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl$FragmentContentDriver.next(XM LDocumentFragmentScannerImpl.java:2755)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumen tScannerImpl.next(XMLDocumentScannerImpl.java:648)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl.next(XMLNSDocumentScannerImpl.java: 140)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanDocument(XMLDocumentFragm entScannerImpl.java:511)
        at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:808)
        at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:737)
        at com.sun.org.apache.xerces.internal.parsers.XMLPars er.parse(XMLParser.java:119)
        at com.sun.org.apache.xerces.internal.parsers.DOMPars er.parse(DOMParser.java:235)
        at com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderImpl.parse(DocumentBuilderImpl.java:284)
        at org.springframework.beans.factory.xml.DefaultDocum entLoader.loadDocument(DefaultDocumentLoader.java: 75)
        at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:396)
        at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:342)
        at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:310)
        at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:143)
        at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:178)
        at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:149)
        at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:212)
        at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:113)
        at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:80)
        at org.springframework.context.support.AbstractRefres hableApplicationContext.refreshBeanFactory(Abstrac tRefreshableApplicationContext.java:123)
        at org.springframework.context.support.AbstractApplic ationContext.obtainFreshBeanFactory(AbstractApplic ationContext.java:422)
        at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:352)
        at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
        at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:83)
        at com.mycompany.service.CourseServiceImplTest.setUpC lass(CourseServiceImplTest.java:30)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(FrameworkMethod.java:44)
        at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExpl osively(FrameworkMethod.java:41)
        at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:27)
        at org.junit.internal.runners.statements.RunAfters.ev aluate(RunAfters.java:31)
        at org.junit.runners.ParentRunner.run(ParentRunner.ja va:236)
        at junit.framework.JUnit4TestAdapter.run(JUnit4TestAd apter.java:39)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnit TestRunner.run(JUnitTestRunner.java:518)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnit TestRunner.launch(JUnitTestRunner.java:1052)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnit TestRunner.main(JUnitTestRunner.java:906)

        Comment


        • #5
          Well as your stacktrace indicates there is no 2.5.6.xsd... There is a 2.5 version which you should reference (or omit the version entirely to get the latest version). The same goes for your aop and context xsd files.

          I also suggest a read of the test chapter of the reference guide.

          Comment


          • #6
            but it wasn't me who choosed the versions it's autogenerated by Netbeans as you can see on here:

            <?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:context="http://www.springframework.org/schema/context"
            xmlns:tx="http://www.springframework.org/schema/tx"

            xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.5.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schem...-aop-2.5.6.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schem...text-2.5.6.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schem...g-tx-2.5.6.xsd
            ">

            </beans>

            Comment


            • #7
              That doesn't tell me anything... The fact remains there is no 2.5.6 xsd the header can be generated by netbeans or not it still does not exist... Only solution change it.

              Comment


              • #8
                i deleted the version:

                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"
                xmlns:context="http://www.springframework.org/schema/context"
                xmlns:tx="http://www.springframework.org/schema/tx"
                
                xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans.xsd
                http://www.springframework.org/schema/aop http://www.springframework.org/schem...-aop.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schem...text.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schem...g-tx.xsd
                ">
                and changed transaction.manager to transactionManager

                Code:
                <tx:annotation-driven transactionManager="transactionManager"/>
                but it's telling me that :
                attribute 'transactionManager' is not allowed to appear in element 'tx:annotation-driven'

                Comment


                • #9
                  problem solved there is no transactionManager it's transaction-manager thanks for your time, but now i'm having another error saying

                  Testcase: com.mycompany.service.CourseServiceImplTest: Caused an ERROR
                  Error creating bean with name 'sessionFactory' defined in class path resource [application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V
                  org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in class path resource [application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V
                  Last edited by skyweb; May 19th, 2011, 09:10 AM.

                  Comment

                  Working...
                  X