xml - spring xml问题

标签 xml spring

我正在尝试编写一个简单的 Spring AOP 应用程序,但我遇到了 xml 配置问题。

我的 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>

我收到此警告和异常:

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'.

还有,我看不懂xmlns

最佳答案

更改 <beans XML 顶部的声明如下所示:

<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">

您只是添加了这个“http://www.springframework.org/schema/aop/spring-aop-3.0.xsd”。 xsi:schemaLocation属性只是一堆对。每对中的第一个是架构 URI,第二个是可以找到架构的 URL。您可以将其视为一个映射:键,然后是值。

关于xml - spring xml问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6943031/

相关文章:

Spring Data + QueryDSL空谓词+谓词链接

java - 如何从 Vaadin/Spring 应用程序提供静态资源?

java - 如何从 unix 时间戳中提取小时数?

xml - 带有 XML::Compile::SOAP::WSS 和 Perl 的 WSSE

php - 从 PHP 中的 XML 链接获取下一个标题

xml - Groovy > 嵌套映射到 Xml

sql-server - 将 SQL Server 中的 XML 列分解为新表

java - KafkaException : class is not an instance of org. apache.kafka.common.serialization.Deserializer

java - Hibernate 逆向工程未生成正确的域代码 STS

java - 如何从xml文件中获取属性?