I was able to run it locally, but when I deployed it, an error occurred. The details of the countermeasures are described.
** 6/15 postscript ** It seems that Maven plugins etc. were released after writing this article.
As mentioned above, it works fine locally using the Maven plugin, but when I deploy it to Azure and run it, I get the following error.
502-Bad Gateway The specified CGI application encountered an error and the server terminated the process.
According to the following, it seems that the old code has stopped working due to the release of the new Runtime. https://stackoverflow.com/questions/50615746/azure-java-function-502-bad-gateway https://github.com/Azure/app-service-announcements/issues/112
It works locally with the old Runtime, so it's okay, but when deployed it runs on the new Runtime, so it seems that an error has occurred.
You can fix it to work with the new Runtime, but as of June 14, 2018, this is not possible yet. This is because the azure-functions-maven-plugin that supports this has not been released yet.
Therefore, we will implement the following as a provisional measure.
Specify the version of Runtime on Azure. Open the Function App "Application Settings" from the Azure portal. Change FUNCTIONS_EXTENSION_VERSION to 2.0.11776-alpha. (The default should be beta.)
In addition, this version is valid until the end of June.
~~ Maven Plugin has not been released, but other parts that need to be dealt with are as follows. In addition, since it will be a half-finished response, it will be an environment that does not work even locally. ~~
** 6/15 postscript ** Since the corresponding Maven Plugin has been released, the following correspondence is OK.
It is assumed that the project was created from Maven Archetype, so if you are customizing it, please read it as appropriate. ~~ In addition, when azure-functions-maven-plugin is released, it seems that it is necessary to modify the version specified in plugin Management. ~~
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-java-core</artifactId>
<version>1.0.0-beta-3</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library</artifactId>
<version>1.0.0-beta-4</version>
</dependency>
Here, the setting to add the jar file defined by pom to the lib folder is set. Originally it was set to exclude azure-functions-java-core, so modify it as follows to exclude azure-functions-java-library.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${stagingDirectory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>runtime</includeScope>
<excludeArtifactIds>azure-functions-java-library</excludeArtifactIds> <!--here-->
</configuration>
</execution>
</executions>
</plugin>
Change the version to 1.0.0-beta-2.
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<version>1.0.0-beta-2</version> <!--here-->
</plugin>
The package has changed and needs to be fixed.
import com.microsoft.azure.serverless.functions.annotation.*;
import com.microsoft.azure.serverless.functions.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;
It seems that serverless is gone.
When it was an update, I couldn't figure out the version specification, so I uninstalled it and reinstalled it.
npm -g uninstall azure-functions-core-tools
npm -g install azure-functions-core-tools@core
As I was writing this article, people who recently started running Azure Functions in Java don't even work locally. (Because if you follow the procedure, a new Runtime will be installed)
For such people, it may be better to lower the version of Runtime and install it.
npm -g uninstall azure-functions-core-tools
npm -g install [email protected]
** 6/15 postscript ** Since the corresponding version has been released, I think that it is better to make modifications so that it can support the new Runtime, instead of lowering the version of Runtime.
Recommended Posts