복붙노트

[SPRING] 일치하는 와일드 카드는 엄격하지만 'tx : annotation-driven'요소에 대한 선언을 찾을 수 없습니다.

SPRING

일치하는 와일드 카드는 엄격하지만 'tx : annotation-driven'요소에 대한 선언을 찾을 수 없습니다.

JSF + Spring + hibernate를 구성하려고하는데 테스트를 실행하려고하지만 application-context.xml 파일에서 "tx : annotation-driven"을 사용할 때이 오류가 발생합니다.

다음은 내 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가 있습니다. 아직 테스트를 구현하지 않았습니다.

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

Course ServiceImpl은 다음과 같습니다.

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

}

해결법

  1. ==============================

    1.appcontext.xml에 몇 가지 오류가 있습니다.

    appcontext.xml에 몇 가지 오류가 있습니다.

  2. ==============================

    2.이것은 다른 사람들을위한 것입니다 (나처럼 :)). spring tx jar / maven 종속성을 추가하는 것을 잊지 마십시오. 또한 appctx의 올바른 구성은 다음과 같습니다.

    이것은 다른 사람들을위한 것입니다 (나처럼 :)). spring tx jar / maven 종속성을 추가하는 것을 잊지 마십시오. 또한 appctx의 올바른 구성은 다음과 같습니다.

    xmlns:tx="http://www.springframework.org/schema/tx"
    

    xsi : schemaLocation = "http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"

    , 실수로 다른 사람이 가질 수있는 잘못된 구성

    xmlns:tx="http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
    

    즉, 여분의 "/spring-tx-3.1.xsd"

    xsi : schemaLocation = "http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"

    다른 말로하면 xmlns (네임 스페이스)에는 거기에 적절한 매핑이 있어야합니다. schemaLocation (네임 스페이스와 스키마). 여기 네임 스페이스는 다음과 같습니다. http://www.springframework.org/schema/tx 스키마 Doc의 네임 스페이스는 다음과 같습니다. http://www.springframework.org/schema/tx/spring-tx-3.1.xsd 이 네임 스페이스 스키마는 jar에 매핑되어 org.springframework.transaction.config에있는 실제 xsd의 경로를 찾습니다.

  3. ==============================

    3.저에게있어서 xsi : schemaLocation 태그에 네임 스페이스가 정의 된 순서가있었습니다 : [버전이 모두 좋았고 이미 트랜잭션 관리자 였기 때문에]

    저에게있어서 xsi : schemaLocation 태그에 네임 스페이스가 정의 된 순서가있었습니다 : [버전이 모두 좋았고 이미 트랜잭션 관리자 였기 때문에]

    오류는 다음과 같습니다.

     http://www.springframework.org/schema/mvc
     http://www.springframework.org/schema/tx
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
     http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
    

    해결 된 문제 :

    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
    
  4. ==============================

    4.tx와 * .xml 파일 앞에 슬래시 (/)가 추가되어 8 시간 동안 문제가 발생했습니다 !!

    tx와 * .xml 파일 앞에 슬래시 (/)가 추가되어 8 시간 동안 문제가 발생했습니다 !!

    내 실수:

    http://www.springframework.org/schema/tx/ http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
    

    보정:

    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
    

    실제로 한 문자 적게는 / 더 많은 시간 동안 프로그래머를 바쁘게 해줍니다!

  5. ==============================

    5.필자의 경우 실제로 이것은 AWS에서 호스팅되는 서버의 증상이었으며 외부 네트워크에 대한 IP가 부족했습니다. springframework.org에서 네임 스페이스를 다운로드하려고 시도하고 연결을 시도하지 않을 것입니다.

    필자의 경우 실제로 이것은 AWS에서 호스팅되는 서버의 증상이었으며 외부 네트워크에 대한 IP가 부족했습니다. springframework.org에서 네임 스페이스를 다운로드하려고 시도하고 연결을 시도하지 않을 것입니다.

  6. ==============================

    6.FWIW 나는이 똑같은 문제를 안고 있었다. 내 xsi : schemaLocation 항목이 잘못된 것으로 판명되었으므로 공식 문서로 이동하여 내 문서를 붙여 넣었습니다.

    FWIW 나는이 똑같은 문제를 안고 있었다. 내 xsi : schemaLocation 항목이 잘못된 것으로 판명되었으므로 공식 문서로 이동하여 내 문서를 붙여 넣었습니다.

    http://docs.spring.io/spring/docs/current/spring-framework-reference/html/transaction.html 섹션 16.5.6

    나는 한 쌍 더 더해야했다. 그러나 그것은 ok이었다. 다음은 이것이 왜이 문제를 해결했는지 알아 보는 것입니다 ...

  7. ==============================

    7.Spring 버전과 xsd 버전이 모두 동일해야합니다. 제 경우에는 Spring 4.1.1을 사용하고 있습니다. 따라서 모든 xsd 버전은 * -4.1.xsd 버전이어야합니다.

    Spring 버전과 xsd 버전이 모두 동일해야합니다. 제 경우에는 Spring 4.1.1을 사용하고 있습니다. 따라서 모든 xsd 버전은 * -4.1.xsd 버전이어야합니다.

  8. ==============================

    8.나는 우디에서 배운다. 강사가 저에게 보여 주어야 할 모든 단계를 따랐습니다. 봄 mvc crud 섹션 devlopment 환경을 설정하는 동안 나는 같은 오류가 발생했습니다 :

    나는 우디에서 배운다. 강사가 저에게 보여 주어야 할 모든 단계를 따랐습니다. 봄 mvc crud 섹션 devlopment 환경을 설정하는 동안 나는 같은 오류가 발생했습니다 :

    <mvc:annotation-driven/> and <tx:annotation-driven transaction-manager="myTransactionManager" />
    

    그럼 난 방금 교체 했어.

        http://www.springframework.org/schema/mvc/spring-mvc.xsd 
    

        http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
    

        http://www.springframework.org/schema/tx/spring-tx.xsd
    

        http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
    

    사실 나는이 두 사이트를 방문했다. http://www.springframework.org/schema/mvc/ 및 http://www.springframework.org/schema/tx/ 최신 버전의 spring-mvc 및 spring-tx, 즉 spring-mvc-4.2.xsd 및 spring-tx-4.2.xsd가 추가되었습니다.

    그래서, 나는 이것을 시도하는 것이 좋습니다. 희망이 도움이됩니다. 고맙습니다.

  9. ==============================

    9.

    Any one can help for me!!!!!!!!!
    <?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:jee="http://www.springframework.org/schema/jee"
            xmlns:lang="http://www.springframework.org/schema/lang"
            xmlns:p="http://www.springframework.org/schema/p"
            xmlns:tx="http://www.springframework.org/schema/tx"
            xmlns:util="http://www.springframework.org/schema/util"
            xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/aop/ http://www.springframework.org/schema/aop/spring-aop.xsd
                http://www.springframework.org/schema/context/ http://www.springframework.org/schema/context/spring-context.xsd
                http://www.springframework.org/schema/jee/ http://www.springframework.org/schema/jee/spring-jee.xsd
                http://www.springframework.org/schema/lang/ http://www.springframework.org/schema/lang/spring-lang.xsd
                http://www.springframework.org/schema/tx/ http://www.springframework.org/schema/tx/spring-tx.xsd
                http://www.springframework.org/schema/util/ http://www.springframework.org/schema/util/spring-util.xsd">
            <context:annotation-config />(ERROR OCCUR)
            <context:component-scan base-package="hiberrSpring" /> (ERROR OCCUR)
            <bean id="jspViewResolver"
                class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="viewClass"
                    value="org.springframework.web.servlet.view.JstlView"></property>
                <property name="prefix" value="/WEB-INF/"></property>
                <property name="suffix" value=".jsp"></property>
            </bean>
            <bean id="messageSource"
                class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
                <property name="basename" value="classpath:messages"></property>
                <property name="defaultEncoding" value="UTF-8"></property>
            </bean>
            <bean id="propertyConfigurer"
                class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
                p:location="/WEB-INF/jdbc.properties"></bean>
            <bean id="dataSource"
                class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
                p:driverClassName="${com.mysql.jdbc.Driver}"
                p:url="${jdbc:mysql://localhost/}" p:username="${root}"
                p:password="${rajini}"></bean>
            <bean id="sessionFactory"
                class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                <property name="dataSource" ref="dataSource"></property>
                <property name="configLocation">
                    <value>classpath:hibernate.cfg.xml</value>
                </property>
                <property name="configurationClass">
                    <value>org.hibernate.cfg.AnnotationConfiguration</value>
                </property>
                <property name="hibernateProperties">
                    <props>
                        <prop key="hibernate.dialect">${org.hibernate.dialect.MySQLDialect}</prop>
                        <prop key="hibernate.show_sql">true</prop>
                    </props>
                </property>
            </bean>
            <bean id="employeeDAO" class="hiberrSpring.EmployeeDaoImpl"></bean>
            <bean id="employeeManager" class="hiberrSpring.EmployeeManagerImpl"></bean>
            <tx:annotation-driven /> (ERROR OCCUR)
            <bean id="transactionManager"
                class="org.springframework.orm.hibernate3.HibernateTransactionManager">
                <property name="sessionFactory" ref="sessionFactory"></property>
            </bean>
        </beans>
    
  10. from https://stackoverflow.com/questions/6058037/the-matching-wildcard-is-strict-but-no-declaration-can-be-found-for-element-tx by cc-by-sa and MIT license