2011-08-04 12 views
5

Próbuję napisać prostą aplikację Spring AOP, ale mam problem z konfiguracją xml.Problem xml wiosna

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

<bean id="audience" class="springaop.Audience"> 
</bean> 

<bean id="sam" class="springaop.Singer"> 
    <property name="id" value="1"></property> 
</bean> 

<aop:config> 
    <aop:aspect ref="audience"> 

     <aop:before pointcut="* springaop.Singer.perform(..)" 
     method="takeSeats"></aop:before> 

    </aop:aspect> 
</aop:config> 

</beans> 

mam to ostrzeżenie i wyjątek:

 
WARNING: Ignored XML validation warning 
    org.xml.sax.SAXParseException: SchemaLocation: schemaLocation value = 'http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop' must have even number of URI's. 

Exception: Line 18 in XML document from class path resource [aop-conf.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:config'. 

Również nie mogę zrozumieć xmlns

Odpowiedz

16

Zmian deklaracji na szczycie XML <beans wyglądać tak:

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

Po prostu dodanie tego „http: //www.springframework.org/schema/aop/spring-aop-3.0.xsd ". Atrybut xsi:schemaLocation to tylko kilka par. Pierwsza z każdej pary to identyfikator URI schematu, a drugi to adres URL, pod którym można znaleźć schemat. Możesz myśleć o tym jako o mapie: klucz, a następnie wartość.

6

Atrybut xsi:schemaLocation muszą mieć parzystą liczbę URI. Każda para wiąże identyfikator URI przestrzeni nazw z lokalizacją XSD. Twój xsi:schemaLocation zawiera trzy identyfikatory URI, więc jest nieprawidłowy. Oto, co przekazuje ci wiadomość.

Musisz podać lokalizację XSD dla http://www.springframework.org/schema/aop

Powiązane problemy