匹配的通配符是严格的,但是找不到元素'tx:annotation-driven'的声明 [英] The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'

查看:81
本文介绍了匹配的通配符是严格的,但是找不到元素'tx:annotation-driven'的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置JSF + Spring + hibernate,并且想运行一个测试,但是当我在application-context.xml文件中使用此"tx:annotation-driven"时,出现此错误:

I am trying 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:

匹配的通配符很严格,但是找不到元素'tx:annotation-driven'的声明

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

这是我的application-context.xml:

Here is my application-context.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: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>

,这是我的CourseServiceImplTest.我还没有执行测试:

and here is my CourseServiceImplTest. I have still not implemented the tests:

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.");
    }

这是CourseServiceImpl:

and here is the CourseServiceImpl:

@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);
    }

}

推荐答案

appcontext.xml中存在一些错误:

You have some errors in your appcontext.xml:

  • 使用* -2.5.xsd

  • Use *-2.5.xsd

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.xsd
  http://www.springframework.org/schema/context 
  http://www.springframework.org/schema/context/spring-context-2.5.xsd
  http://www.springframework.org/schema/tx 
  http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"

  • tx:annotation-drivencontext:component-scan中的错别字(.代替-)

  • Typos in tx:annotation-driven and context:component-scan (. instead of -)

    <tx:annotation-driven transaction-manager="transactionManager" />
    <context:component-scan base-package="com.mmycompany" />
    

  • 这篇关于匹配的通配符是严格的,但是找不到元素'tx:annotation-driven'的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆