简体   繁体   中英

Replace property file value with another value dynamically- Spring maven

i have 2 external properties security.properties and env.properties and i have a key in security.properties as key1 and i want to replace this key1 value based on the env.properties key1

ex:

security.properties
hibernate.connection.url=jdbc:oracle:thin:@localhost:4521/NGI

env.properties
jdbc.url=jdbc:oracle:thin:@localhost:4521/NGI (it defers based on the environment)

i want to replace the hibernate.connection.url to jdbc.url based on the loaded environment.

I tried the following option, but i get a build failure error

<configuration>
           <file>target/${project.artifactId}/security.properties</file>
           <replacements>
               <replacement>
                   <token>${hibernate.connection.url}</token>
                   <value>${jdbc.url}</value>
               </replacement>         
           </replacements>
       </configuration>

please share your suggestions

I believe, what you missed in your pom was loading the env properties. You need to load that file using maven properties plugin .

However, what everyone is trying to tell you, is to keep the values from the env.properties in different profiles in your pom.xml and activate the right profile depending on your targeted environment.

What about keeping all these URLs as property values in pom.xml instead of bunch of ".properties" files? Their values can be easily changed and overrided using profiles and they can be substituted into ".properties" files during filtered resource copying phase of Maven build.

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