Home > Software design >  Is it possible to use yaml's profile variable in spring mybatis's mapper xml?
Is it possible to use yaml's profile variable in spring mybatis's mapper xml?

Time:03-04

It is possible to use yaml's profile variable in spring mybatis's mapper xml?

If is it possible, how i can use?

CodePudding user response:

I think you cannot do this in a simple way as both *.yml and *.xml files are loaded at application start-up time. Instead you can propagate values into placeholders within XML at build time using maven/gradle plugin.

E.g. for maven this can be done with maven-resource-plugin:

For example, if we have a resource src/main/resources/hello.txt containing

Hello ${name}

and a pom.xml with

<project>
  ...
  <name>My Resources Plugin Practice Project</name>
  ...
  <build>
    ...
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
      ...
    </resources>
    ...
  </build>
  ...
</project>

Upon calling mvn resources:resources will create a resource output in target/classes/hello.txt which contains:

Hello My Resources Plugin Practice Project

I.e. maven takes a value from <name/> tag and puts it into placeholder ${name}.

  • Related