skip to Main Content

I have created an application using java spring boot. I want to deploy it in the azure function app and im deploying it in the azure function app via vs code by using the below commands

  • ./mvnw clean package
  • ./mvnw azure-functions:deploy

when i run the second command im getting "device code consumer is not configured." error and the build is failing.

Can any one answer my question please.

i tried both the commands by configuring the pom.xml file with the required azure function app details and deployed it in the function app.

2

Answers


  1. To resolve this issue, login to Azure by running the below commands in Terminal:

    1. az login
    2. az account set --subscription <your_subscription_id>
    

    You can also specify the function to use Azure CLI credential explicitly with below configuration under azure-functions-maven-plugin in pom.xml:

    <configuration>
         <auth><type>azure_cli</type></auth>
    </configuration>
    

    Run the function locally using the commands:

    mvn clean install
    mvn azure-functions:run
    

    pom.xml:

        <name>Azure Java Functions</name>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <java.version>17</java.version>
            <azure.functions.maven.plugin.version>1.36.0</azure.functions.maven.plugin.version>
            <azure.functions.java.library.version>3.1.0</azure.functions.java.library.version>
            <functionAppName>javafn-1727176226852</functionAppName>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>com.microsoft.azure.functions</groupId>
                <artifactId>azure-functions-java-library</artifactId>
                <version>${azure.functions.java.library.version}</version>
            </dependency>
            <!-- Test -->
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter</artifactId>
                <version>5.4.2</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-core</artifactId>
                <version>2.23.4</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <encoding>${project.build.sourceEncoding}</encoding>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>com.microsoft.azure</groupId>
                    <artifactId>azure-functions-maven-plugin</artifactId>
                    <version>${azure.functions.maven.plugin.version}</version>
                    <configuration>
                        <appName>${functionAppName}</appName>
                        <resourceGroup>java-functions-group</resourceGroup>
                        <region>westus</region>
                        <appServicePlanName>java-functions-app-service-plan</appServicePlanName>
                        <runtime>
                            <os>windows</os>
                            <javaVersion>17</javaVersion>
                        </runtime>
                        <appSettings>
                            <property>
                                <name>FUNCTIONS_EXTENSION_VERSION</name>
                                <value>~4</value>
                            </property>
                        </appSettings>
                    </configuration>
                    <executions>
                        <execution>
                            <id>package-functions</id>
                            <goals>
                                <goal>package</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <!--Remove obj folder generated by .NET SDK in maven clean-->
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                    <configuration>
                        <filesets>
                            <fileset>
                                <directory>obj</directory>
                            </fileset>
                        </filesets>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    
    

    Deploy the function to Azure function app using the command mvn azure-functions:deploy:

    C:Usersunamejavafn> mvn azure-functions:deploy
    [INFO] Scanning for projects...
    [INFO] 
    [INFO] ------------------------< com.function:javafn >-------------------------
    [INFO] Building Azure Java Functions 1.0-SNAPSHOT
    [INFO]   from pom.xml
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO]
    [INFO] --- azure-functions:1.36.0:deploy (default-cli) @ javafn ---
    [INFO] Auth type: AZURE_CLI
    [INFO] Username: uname
    [INFO] Subscription: your_subscription(d93XXX-8856-a7f4589e52bc)
    [INFO] Start creating Storage Account(d6ac9aXXX46f2b6c8)...
    [INFO] Storage Account(d6ac9ab1XXb46f2b6c8) is successfully created.
    [WARNING] Skip validation as schema appservice/CreateAppServicePlan was not registered
    [INFO] Start creating App Service plan (java-functions-app-service-plan)...
    [INFO] App Service plan (java-functions-app-service-plan) is successfully created
    [INFO] Set function worker runtime to java.
    [INFO] Start creating Function App(javafn-1727176226852)...
    [INFO] Function App(javafn-1727176226852) is successfully created
    [INFO] Starting deployment...
    [INFO] Trying to deploy artifact to javafn-1727176226852...
    [INFO] Successfully deployed the artifact to https://javafn-1727176226852.azurewebsites.net
    [INFO] Deployment succeed
    [INFO] Syncing triggers and fetching function information
    [INFO] Querying triggers...
    [INFO] HTTP Trigger Urls:
             HttpExample : https://javafn-1727176226852.azurewebsites.net/api/httpexample
    
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  02:54 min
    [INFO] Finished at: 2024-09-24T17:10:53+05:30
    [INFO] ------------------------------------------------------------------------
    

    Deployed the function to Azure successfully:

    Portal:

    enter image description here

    Login or Signup to reply.
  2. Seems the problem is with the authentication to Azure while deploying the code. Before you deploy make sure you login to the Azure subscription using the az cli

    az login

    you can also refer my articles, it has tested sample code:

    https://www.baeldung.com/java-azure-functions

    https://www.baeldung.com/spring-cloud-function-microsoft-azure

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search