Comportamiento extraño con Spring config y perfiles de Maven

I have this weird behavior working with the Maven <filter> tag and Spring configs . My understanding is that a Spring config is a plain XML file to Maven but I'm encountering issues with the <context:component-scan base-package=""/> tag . The test XML file is as below

<beans xmlns="" 

    <!-- Import the DataSource configurations -->
    <import resource="classpath:spring/MyDataSource.xml"/>

   <!--  Property File location --> 
   <context:property-placeholder location="${}"/>

    <!--The services are auto-detected POJOs labeled with the @Service annotation.-->
<context:component-scan base-package=""/>


and the Maven profiles configuration as below



Contents of are

My issue was that the Maven profile filtering was not working and the property ${} was not getting replaced during the packaging process . It stated working when I removed the <context:component-scan base-package=""/> tag and hence I placed it below the property which needs to be filtered . Now everything works fine . My question is what's the issue with <context:component-scan base-package=""/> ?

preguntado el 02 de febrero de 12 a las 10:02

1 Respuestas

yo no pienso eso <context:component-scan base-package=""/> but the comment above

<!--The services are auto-detected POJOs labeled with the @Service annotation.-->

El @ tiene un significado especial en maven fitlers.

To be honest I have the feeling that there are to many overlapping in syntax between spring configuration files and maven filters to use them together. My "solution" is to use (as long as possible) two files for the spring configuration.

  • a Property file, that is manipulated by spring filters
  • a normal Spring configuration file (with placeholders) that uses a PropertyPlaceholder Configurer to load the property file.

Respondido 02 Feb 12, 15:02

You hit right on target . It would be nice if you can tell me what are '@' used for in Maven filters ? What does Maven understand when it sees one ? - Aravind A

I understand but in our case I can't avoid it as the PropertyPlaceholder's location comes in from a property file based on the environment -Linux has a different path for property file which differs from Windows location . Thanks anyhow . - Aravind A

@Aravind A: the idea behinde that properties files, it that they are always the same file (with different conntent) and they are at the same location, in the classpath, so win vs. does not matter. - Ralph

I would have preferred the same but the clients want it to be accessible externally to change some values which affect the UI- Not my call . - Aravind A

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.