developer tip

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

optionbox 2020. 11. 23. 08:02
반응형

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


첫 번째 봄 프로젝트를 시도하는 동안 다음 오류가 발생합니다.

Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan

다음은 다음과 같습니다 applicationContext.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:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

        <context:component-scan base-package="com.xyz" />

</beans>

오류의 원인은 무엇입니까?


컨텍스트 네임 스페이스의 스키마 위치를 지정하지 않았습니다. 이것이이 특정 오류의 원인입니다.

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

이 스키마 위치 경로가 잘못되었습니다.

http://www.springframework.org/schema/beans

올바른 경로는 다음으로 끝나야합니다 /.

http://www.springframework.org/schema/beans/

나는 문제가 있었다

Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'security:http'

나를 위해 클래스 경로에 spring-security-config jar를 추가해야했습니다.

http://docs.spring.io/spring-security/site/docs/3.1.x/reference/ns-config.html

편집하다:

pom에 올바른 종속성이있을 수 있습니다.

그러나...

여러 스프링 종속성을 사용하고 단일 jar로 조립 META-INF/spring.schemas하는 경우 spring.schemas다른 스프링 종속성 이을 덮어 썼을 것입니다 .

(조립 된 항아리에서 해당 파일을 추출하면 이해할 수 있습니다.)

Spring 스키마는 다음과 같은 줄의 묶음입니다.

http\://www.springframework.org/schema/p=org.springframework.beans.factory.xml.SimplePropertyNamespaceHandler
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd

그러나 다른 종속성이 해당 파일을 덮어 쓰면 정의가 http에서 검색되고 방화벽 / 프록시가 있으면 가져 오지 못합니다.

한 가지 해결책은 spring.schemas 및 spring.handlers를 단일 파일에 추가하는 것입니다.

검사:

단일 항아리에 여러 스프링 종속성을 병합 할 때 spring.handlers / spring.schemas를 덮어 쓰지 않도록하는 아이디어


이 오류는 필요한 XSD가 포함 된 jar 파일이 배치 된 클래스 경로에 포함되지 않은 경우에도 발생할 수 있습니다.

컨테이너에서 종속성을 사용할 수 있는지 확인하십시오.


STS를 사용하는 경우 Eclipse에서 구성 파일을 "Bean 구성"파일로 표시 할 수 있습니다 (XML 파일을 만들거나 마우스 오른쪽 버튼으로 클릭 할 때 지정할 수 있음).

Spring 도구> Bean 구성으로 추가

프로젝트에는 Spring Nature가 있어야합니다 (예 : maven 프로젝트를 마우스 오른쪽 버튼으로 클릭).

Spring Tools> Spring Project Nature 추가

그런 다음 spring.xml기본적으로 Spring Config Editor로 열립니다.

연결 프로그램> Spring Config Editor

이 편집기에는 네임 스페이스 탭이 있습니다.

Spring Config Editor-네임 스페이스 탭

이를 통해 네임 스페이스를 지정할 수 있습니다.

Spring Config Editor-네임 스페이스 예제

의존성 (maven 프로젝트 사용)에 따라 다르므로 spring-txmaven의 pom.xml에 정의되지 않은 경우 옵션이 없으므로 일치하는 와일드 카드가 엄격하지만 요소에 대한 선언을 찾을 수 없습니다. 'tx : annotation-driven' 'context : component-scan' 문제 ...


It's too late but somewhat may useful to others

The matching wildcard is strict, but no declaration can be found for element 'context:component-scan

which Means you have Missed some Declarations or The Required Declarations Not Found in Your XML

In my case i forgot to add the follwoing

After Adding this the Problem Gone away

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

when you add context:component-scan for the first time in an xml, the following needs to be added.

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

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

The correct path shouldn't end with "/", I had it wrong that caused the trouble

Right way:

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


이 두 스키마 위치를 추가하십시오. 불필요한 스키마를 모두 추가하는 대신 충분하고 효율적입니다.

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

네임 스페이스 선언 및 스키마 위치를 사용하여 네임 스페이스 사용 구문을 확인할 수도 있습니다.

<beans xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation= http://www.springframework.org/`enter code here`schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

<context:annotation-driven/>   <!-- This is wrong -->
<context:annotation-config/> <!-- This should work -->

아래와 같이 http로 xmlns 컨텍스트를 추가하십시오.

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


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

위의 링크가 포함되어야합니다.

    <context:property-placeholder location="classpath:sport.properties" />


    <bean id="myFortune" class="com.kiran.springdemo.HappyFortuneService"></bean>

    <bean id="myCoach" class="com.kiran.springdemo.setterinjection.MyCricketCoach">
        <property name="fortuner" ref="myFortune" />

        <property name="emailAddress" value="${ipl.email}" />
        <property name="team" value="${ipl.team}" />

    </bean>


</beans>

참고 URL : https://stackoverflow.com/questions/13589470/the-matching-wildcard-is-strict-but-no-declaration-can-be-found-for-element-co

반응형