Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring xml problem

Tags:

spring

xml

I'm trying to write a simple Spring AOP app, but I have problem with the xml configuration.

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

I get this warning and exception:

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

Also, I cant understand the xmlns

like image 324
Evgeni Dimitrov Avatar asked Aug 04 '11 14:08

Evgeni Dimitrov


People also ask

Is Spring XML still used?

Before Spring 3.0, XML was the only way to define and configure beans. Spring 3.0 introduced JavaConfig, allowing us to configure beans using Java classes. However, XML configuration files are still used today. In this tutorial, we'll discuss how to integrate XML configurations into Spring Boot.

Does Spring support XML?

Spring Integration's XML support extends the core of Spring Integration with the following components: Marshalling Transformer.

Does Spring boot avoid XML configuration?

Is it possible to avoid using xml in Spring or better to mix xml files and annotations? Yes, it is. Spring now promotes Java configuration, and it's perfectly doable (I'm doing it) and even easy to only use Java to configure your Spring app. Even without using Boot.

Does Spring 5 support XML based configuration?

Spring allows you to configure your beans using Java and XML. In this guide, we will explore how to use XML and Java Configurations with Spring Boot. We will understand how to load these configurations into a Spring Application Context.


1 Answers

Change the <beans declaration at the top of the XML to look like this:

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

You're just adding this "http://www.springframework.org/schema/aop/spring-aop-3.0.xsd". The xsi:schemaLocation attribute is just a bunch of pairs. The first of each pair is a schema URI, the second is the URL where the schema can be found. You can think of it as a map: key, then value.

like image 188
sblundy Avatar answered Oct 19 '22 05:10

sblundy