Spring-boot: mvn spring-boot:run ignores resource filtering

Created on 28 May 2014  路  14Comments  路  Source: spring-projects/spring-boot

Hi,
When you run

mvn spring-boot:run -P dev

it ignores maven resource filtering. I have application.properties file with following entry

spring.profiles.active = ${active.profiles}

In my pom.xml I have

    <profile>
      <id>dev</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>

      <properties>
        <active.profiles>dev</active.profiles>
      </properties>
    </profile>

When i do classic mvn package evertyhing works as expected
application.properties becomes:

spring.profiles.active = dev

When I run Application class from eclipse with profile set in m2e plugin, everything also works as expected.

Any ideas why mvn spring-boot:run -P dev ignores resource filtering. ?

invalid

Most helpful comment

Have you read the release notes by any chance? Are you using the parent and the ${} notation (instead of @@)?

All 14 comments

The spring-boot:run command adds src/main/resources directly to the classpath. This enables hot reloading tricks were you can save a static web resource and refresh the browser without restarting the app. My guess is that the non filtered version is being added back by the run plugin.

@snicoll any ideas for a work around?

One workaround is to use "mvn exec:java". You lose the hot reload capability that way, so maybe for such a simple use of filtering it would be better to use "mvn spring-boot:run" and a second "application.properties" in the base dir.

Please check the doc (section "Running the application"). The behaviour that @philwebb described can be disabled using the addResources option.

Duplicates #749

FYI that's a 1.1 feature

Hello.
It is solving problem, but partially.
Now we have alternative hot deploy or maven based resource filter.
It would be very nice to have both somehow.
Maybe plugin can handle some exclusions/black list of files, that should be served from target directory.

I don't see that coming. Think about classpath entries: your src/main/resources is a classpath entry and your target/classes is another one. When you're looking up for a resource, the first one that's found is returned (and obviously addResources add src/main/resources first).

If I understand correctly, you'd like some non filtered files to be hot deployable while others, in the same directory, would not. That's not in our hands.

Maybe you could split these in separate directories and then use the folders attribute of the plugin to just add the one that is not filtered? If you try that and it works, please report here as it's worth documenting.

Thought I'd share in case anyone else lands here like I did. I got the suggested workaround involving the folders attribute of the plugin working.

In my case I wanted to keep certain resources outside src/main/resources, allow hot reloading of said resources and apply filtering to the application.properties file under src/main/resources. Specifically the following plugin config worked for me:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <addResources>false</addResources>
        <folders>
            <folder>src/main/public</folder>
        </folders>
    </configuration>
</plugin>

I have used jfsoul's solution for this problem under Spring Boot 1.2.4.RELEASE and it worked fine.
Now I moved to Spring 1.3.0.RELEASE and this stopped working: resource filtering no longer seems to work.
Has anyone experienced this problem in Spring 1.3.0.RELEASE ?

Have you read the release notes by any chance? Are you using the parent and the ${} notation (instead of @@)?

Cool, I have tried what you suggested and it works fine with Spring Boot 1.3.0.RELEASE . The entry in my application.properties file looks like this:

[email protected]@

Many thanks for pointing this out.

Thanks the @foo@ helped me too.

Thanks for the answer @foo@...... I was breaking my head.....

It was so hard to find the solution, @foo@ is working. Why is it, that spring boot is not just using ${foo} as described on so many maven examples?

@VIIgit this issue is closed so it's not a great place for questions (that should go on stackoverflow anyway). There is a comment (https://github.com/spring-projects/spring-boot/issues/980#issuecomment-158873315) in this very issue that links to the release notes.

Was this page helpful?
0 / 5 - 0 ratings