【发布时间】:2018-02-23 21:26:25
【问题描述】:
谁能帮我找出一个 Maven Java 项目中的 Azure 函数来读取 MongoDB 数据库?
我正在努力在 github 或 Microsoft 的 Azure 文档中找到任何有用的示例。
这是我目前所拥有的——尽管它无法编译,因为它无法访问我在我打算包含的单独库中定义的类。
我的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>CRUD Azure Functions</name>
<version>1.0.0</version>
<artifactId>crud-azure-functions</artifactId>
<description>Experimenting with Azure Functions</description>
<packaging>jar</packaging>
<parent>
<artifactId>my-parent-module</artifactId>
<groupId>com.snoop.dougg</groupId>
<version>1.0.0</version>
</parent>
<properties>
<start-class>com.snoop.dougg.azure</start-class>
</properties>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-java-core</artifactId>
<version>1.0.0-beta-2</version>
</dependency>
<dependency>
<groupId>com.snoop.dougg</groupId>
<artifactId>my-common-lib</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<version>0.1.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<configuration>
<resourceGroup>java-functions-group</resourceGroup>
<appName>crud-azure-functions</appName>
<region>Central US</region>
<appSettings>
<property>
<name>FUNCTIONS_EXTENSION_VERSION</name>
<value>beta</value>
</property>
</appSettings>
</configuration>
<executions>
<execution>
<id>package-functions</id>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<outputDirectory>${project.basedir}</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>**/*jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<outputFile>${project.basedir}/${project.artifactId}-${project.version}.jar</outputFile>
<shadedArtifactAttached>false</shadedArtifactAttached>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
然后这是我的 Java 代码:
package com.snoop.dougg.azure;
import com.snoop.dougg.common.model.mongodb.Item;
import com.microsoft.azure.serverless.functions.ExecutionContext;
import com.microsoft.azure.serverless.functions.HttpRequestMessage;
import com.microsoft.azure.serverless.functions.HttpResponseMessage;
import com.microsoft.azure.serverless.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.serverless.functions.annotation.FunctionName;
import com.microsoft.azure.serverless.functions.annotation.HttpTrigger;
import com.microsoft.azure.serverless.functions.annotation.TableInput;
import javax.servlet.http.HttpServletResponse;
import java.util.Optional;
public class ItemCrudFunctions {
public static void main() {}
@FunctionName("DouggHelloWorld")
public HttpResponseMessage<String> helloWorld(
@HttpTrigger(name = "req", methods = {"get"}, authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
return request.createResponse(HttpServletResponse.SC_OK, "Good news everyone!");
}
@FunctionName("ItemRetrieval")
public HttpResponseMessage<Item> retrieveItem(
@HttpTrigger(name = "retrieveItem",
route = "/item/{itemId}",
methods = {"get"},
authLevel = AuthorizationLevel.FUNCTION)
HttpRequestMessage<Optional<String>> requestMessage,
@TableInput(name = "itemTableInput",
tableName = "item",
connection = "AzureWebJobsStorage",
rowKey = "{itemId}") Item item) {
return requestMessage.createResponse(HttpServletResponse.SC_OK, item);
}
}
但我收到一个错误:找不到符号:类项目,最重要的是,我不知道如果它编译了它是否还能工作。到目前为止,我完全找不到任何好的 Maven Java Azure Functions 示例......
【问题讨论】:
-
您好,我的回答对您有帮助吗?
-
您好,谢谢!我仍然无法从我的其他模块导入类,但我会尽快通知您。
标签: java mongodb maven azure azure-functions