1

I can see that we can define a secure connection string form portal, and than can access those variables in our application.I found many examples to do it in ASP.NET, like defining the keys in web.config. But i can not find any example focusing on accessing these connection strings defined via portal from Spring Boot app. Any help in that direction would be useful

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
Amit_Hora
  • 716
  • 1
  • 8
  • 27
  • 1
    Hi Amit, take a look here https://buildazure.com/2015/11/30/azure-web-app-application-settings/ and here https://buildazure.com/2015/12/01/azure-web-app-connection-strings/ . As Spring Boot is a Java style app you can find an example under the Java section. Hope this helps. – techmike2kx Jul 04 '17 at 06:34
  • Thanks a lot. I was looking looking for something like this only – Amit_Hora Jul 04 '17 at 06:37

2 Answers2

2

See this article from Stefan: How Application Strings and Connection Strings Work in Azure App Service

Azure app service exposes them in the form of environment variables at runtime to the web app. There is a naming convention in place which makes it easier to retrieve them.

For app settings the name of the corresponding environment variable is prepended with APPSETTING_. For connection strings, it depends on the type of DB that has been configured. See below

  • For SQL Azure it is SQLAZURECONNSTR_
  • For SQL Database hosted on Azure VM it is SQLCONNSTR_
  • For MySQL database it is MYSQLCONNSTR_
  • For any other type of databases it is CUSTOMCONNSTR_

In Java, you can use the System.getenv() function to retrieve the environment variables. Refer the document on how to use this: public static String getenv(String name)

You can pass the environment variable to this function to get it working. For example

String envStr = System.getenv("APPSETTING_TestSetting");
Kaushal Kumar Panday
  • 2,329
  • 13
  • 22
1

If Azure exposes these secure strings as environment variables, you can name them to override application properties using the following format:

Property name my.secret.password can be overriden with environment variable MY_SECRET_PASSWORD.

You can also use them directly in your application.properties

my.secret.password=${SUPER_SECRET_ENV_VARIABLE}
Strelok
  • 50,229
  • 9
  • 102
  • 115