How to pass spring active profile while running a azure function with spring cloud function

Urmila Choudhary 0 Reputation points
2023-03-22T09:26:43.8566667+00:00

While running a azure function with spring cloud function on local with the below command

mvn azure-functions:run -Dspring.profiles.active=local

User's image

Active profile for spring is not getting saved it still point to default profile. Is there a way to set spring active profile for azure function?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,978 questions
Azure Spring Apps
Azure Spring Apps
An Azure platform as a service for running Spring Boot applications at cloud scale. Previously known as Azure Spring Cloud.
124 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,476 Reputation points
    2023-03-29T06:04:28.17+00:00

    @Urmila Choudhary

    1. In your Azure Function app settings, add an environment variable called SPRING_PROFILES_ACTIVE with the value of the active profile you want to use.
    2. In your Spring Cloud Function code, use the @Profile annotation to specify the beans that should be activated for the active profile. For example, if you have a bean that should only be active for the "dev" profile, you can annotate it like this:
        @Bean
        @Profile("dev")
        public MyBean myBean() {
            return new MyBean();
        }
        
        ```
        
        
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.