04-17.eri-test 使用适用于Azure Functions的新Gradle插件部署Spring Boot无服务器应用程序...

Introducing the new Gradle plugins for 蔚蓝

对于构建和部署Java项目,蔚蓝一直提供强大的Maven支持,但缺少Gradle支持. As many people love Gradle, in particular when building complex projects, I was thrilled to learn that a new set of Gradle plugins were being developed! They will all be Open Source, and their code will be available on GitHub at https:// github.com/microsoft/azure-gradle-plugins.

The first plugin to be released is the one for Azure Functions, at https:// github.com/microsoft/azure-gradle-plugins/tree/master/azure-functions-gradle-plugin. Azure Functions is the Azure serverless offer, and you can use it to run your Java workloads in a managed, event-driven, fully scalable and inexpensive environment.

If you want to run this Gradle plugin for a simple Java serverless application, the full documentation is available on the Microsoft Docs website. 这对于简单的Java应用程序很有用,您可以将其用于非常简单的Function,但是对于更复杂的应用程序,那些通常会从使用Gradle中受益的应用程序呢?

Running Spring Boot in a serverless environnement

Thanks to Microsoft's work with Pivotal/VMWare, you can run Spring Boot on Azure Functions using the Spring Cloud Function project, which has specific Azure support.

If you want to test Spring Cloud Function and Azure Functions, I maintain the official sample application at https://github.com/Azure-Samples/hello-spring-function-azure. 默认情况下,这是使用Maven的,在此博客中,我们将了解如何将其与新的Gradle插件一起使用.

Using the new Gradle plugin to deploy Spring Boot to Azure Functions

I have created a specific gradle branch in the official sample project, which you can check at https://github.com/Azure-Samples/hello-spring-function-azure/tree/gradle.

使用该代码,您将能够使用新的Azure Gradle插件将Spring Cloud Function应用程序部署到Azure Functions。

它使用一种特定的技巧使Azure Functions运行“主” Spring Boot类,这就是为什么我们在build.gradle文件:

罐子{
     清单{
         属性“ Main-Class”:“ com.example.HelloFunction”
     }
 }

上面的代码块将创建一个特定的Java清单文件,该文件指向主Spring Boot类,以便Azure Functions将其执行。

如果您查看此应用程序的Maven版本,我们将复制特定的local.settings.json文件以实现相同的目标(帮助Azure Functions查找主类)。 使用Gradle,此解决方案看起来更优雅。

然后,其余配置将正常使用Gradle插件:

天蓝色功能{
     resourceGroup ='我的弹簧功能资源组'
     appName ='我的弹簧功能'
     appSettings {
         WEBSITE_RUN_FROM_PACKAGE ='1'
         FUNCTIONS_EXTENSION_VERSION ='〜2'
         FUNCTIONS_WORKER_RUNTIME ='java'
         MAIN_CLASS ='com.example.HelloFunction'
     }
     认证{
         类型='azure_cli'
     }
     //启用本地调试
     // localDebug =“ transport = dt_socket,server = y,suspend = n,address = 5005”
     部署{
         类型='run_from_blob'
     }
 }
  • 您将需要配置将在其中运行功能的特定Azure资源组。
  • 您将需要提供一个独特的appName到您的功能:此名称在所有Azure中都应该是唯一的,因此通常人们在其名称前加上用户名。
  • 我们正在使用最新的FUNCTIONS_EXTENSION_VERSION在撰写本文时可用,因为它在运行Java时具有更好的冷启动性能。

现在已经安装了插件,您可以使用以下Gradle命令:

gradle azureFunctionsRun

这将在本地运行Azure Functions,因此这是开发和调试Function的最佳方法。

gradle azureFunctionsPackage

这将打包您的应用程序,因此可以将其部署到Azure Functions。

gradle azureFunctionsDeploy

这会将您的Function部署到Azure Functions,因此可以在云中使用。

然后,该应用程序的工作原理与使用Maven构建的应用程序完全相同! 因此,您可以通过执行cURL请求来对其进行测试,如下所示:

curl https://<YOUR_SPRING_FUNCTION_NAME>.azurewebsites.net/api/hello -d “ {\“name\“:\“Azure\“}”

from: https://dev.to//azure/using-the-new-gradle-plugin-for-azure-functions-to-deploy-spring-boot-serverless-applications-4594

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值