Quantcast
Channel: Spring and Azure function - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Spring and Azure function

$
0
0

Does Spring work with Azure functions?

For example: Rest API that the code inside uses "Autowired" annotation (After running mvn azure-functions:run I've got NullPointerException on "myScriptService").

import java.util.*;import com.microsoft.azure.serverless.functions.annotation.*;import com.microsoft.azure.serverless.functions.*;import com.company.ScriptService;import org.springframework.beans.factory.annotation.Autowired;/** * Azure Functions with HTTP Trigger. */public class Function {    @Autowired    ScriptService myScriptService;    /**     * This function listens at endpoint "/api/hello". Two ways to invoke it using "curl" command in bash:     * 1. curl -d "HTTP Body" {your host}/api/hello     * 2. curl {your host}/api/hello?name=HTTP%20Query     */    @FunctionName("myhello")    public HttpResponseMessage<String> hello(            @HttpTrigger(name = "req",                         methods = "post",                         authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,                        final ExecutionContext context) {        context.getLogger().info("Java HTTP trigger processed a request.");        // Parse query parameter        String query = request.getQueryParameters().get("name");        String name = request.getBody().orElse(query);                        if (name == null) {            return request.createResponse(400, "Please pass a name on the query string or in the request body");        } else {            return request.createResponse(200, "Hello, "+ name  +", myScriptService.isEnabled(): "+ myScriptService.isEnabled());        }    }}

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images