Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot property expansion not working after switching from Eclipse to IntelliJ

Our app has for properties that we pick up dynamically from the Maven project files.

info:
  build:
    artifact: @project.artifactId@
    name: @project.name@
    description: @project.description@
    version: @project.version@

http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-application-info-automatic-expansion-maven

When we were using Eclipse these were not a problem, but now on moving to InelliJ the app won't startup unless I provide some hardcoded values for those dynamic properties.

I get this error:

19:47:20.962 [main] INFO  com.edlogics.ElrcApplication - Spring Boot configuration: profiles = [local, chris]
19:47:20.968 [main] INFO  com.edlogics.ElrcApplication - Spring Boot configuration: properties = {}
Exception in thread "main" while scanning for the next token
found character '@' that cannot start any token. (Do not use @ for indentation)
 in 'reader', line 74, column 11:
        name: @project.name@
              ^

 org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:420)
 org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:226)
 org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:586)
 org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
 org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143)
 org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:132)
 org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229)
 org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155)
 org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229)
 org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155)
 org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229)
 org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155)
 org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122)
...

Process finished with exit code 1

I realize that @ is not a valid YAML character, just not sure how this was working in Eclipse and not in IntelliJ

Edit:

One thing that I left out of the original questions is that we have a multi-module project. It's the project's root pom that inherits from spring-boot-starter-parent that has this:

        <resources>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/application.yml</include>
                <include>**/application.properties</include>
            </includes>
        </resource>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
            <excludes>
                <exclude>**/application.yml</exclude>
                <exclude>**/application.properties</exclude>
            </excludes>
        </resource>
    </resources>

And in our project it is a submodule that is in need of the filtering. The application.yml file is in the correct location of the submodule and Eclipse did not seem to mind that it was a submodule. I know that Eclipse and IntelliJ treat multi-module projects a little differently (Eclipse has flat structure while IntelliJ is hierarchical).

like image 809
Chris Savory Avatar asked Apr 25 '16 20:04

Chris Savory


2 Answers

Turns out that the resource filtering was working in IntelliJ. There was one property, @project.name@ out of the four that was not being filtered correctly. Somehow this wasn't a problem in Eclipse. So we just removed that property from application.yml since we weren't using it.

Also, right-clicking on the pom.xml and selecting Maven then reimport seems to help with this. This especially helps if IntelliJ does not currently recognize yoru project as a Maven project. enter image description here

like image 51
Chris Savory Avatar answered Nov 12 '22 05:11

Chris Savory


It worked for me:

artifact: '@project.artifactId@'

Just kept the value within single quotes

like image 7
Mukit09 Avatar answered Nov 12 '22 05:11

Mukit09