简体   繁体   中英

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

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

If is it possible, how i can use?

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.

Eg 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM