[英]Error running Spring Boot Azure Function App
I was trying to run this example .我试图运行这个例子。 I made some changes in the function handlers,
pom.xml
and project structure but I don't think they would change the way the app runs.我对 function 处理程序、
pom.xml
和项目结构进行了一些更改,但我认为它们不会改变应用程序的运行方式。
Anyway, my problem occurs when I run ./mvnw azure-functions:run
, for some reason it's not finding my handler.无论如何,当我运行
./mvnw azure-functions:run
时,我的问题出现了,由于某种原因它没有找到我的处理程序。
Functions:
Hello: [GET] http://localhost:7071/api/hello
For detailed output, run func with --verbose flag.
[2021-06-17T17:10:26.980Z] Received FunctionLoadResponse for functionId:1a1ed97a-ac24-43f8-870a-b39887543787
[2021-06-17T17:10:26.982Z] Worker failed to function id 1a1ed97a-ac24-43f8-870a-b39887543787.
[2021-06-17T17:10:26.982Z] Result: Failure
[2021-06-17T17:10:26.982Z] Exception: ClassNotFoundException: com.example.app.modules.HelloHandler
[2021-06-17T17:10:26.982Z] Stack: java.lang.ClassNotFoundException: com.example.app.modules.HelloHandler
[2021-06-17T17:10:26.982Z] at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
[2021-06-17T17:10:26.982Z] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
[2021-06-17T17:10:26.982Z] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
[2021-06-17T17:10:26.982Z] at java.base/java.lang.Class.forName0(Native Method)
[2021-06-17T17:10:26.982Z] at java.base/java.lang.Class.forName(Class.java:398)
[2021-06-17T17:10:26.982Z] at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.getContainingClass(EnhancedJavaMethodExecutorImpl.java:63)
[2021-06-17T17:10:26.982Z] at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.<init>(EnhancedJavaMethodExecutorImpl.java:22)
[2021-06-17T17:10:26.982Z] at com.microsoft.azure.functions.worker.broker.FactoryJavaMethodExecutor.getJavaMethodExecutor(FactoryJavaMethodExecutor.java:20)
[2021-06-17T17:10:26.982Z] at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.loadMethod(JavaFunctionBroker.java:38)
[2021-06-17T17:10:26.982Z] at com.microsoft.azure.functions.worker.handler.FunctionLoadRequestHandler.execute(FunctionLoadRequestHandler.java:27)
[2021-06-17T17:10:26.982Z] at com.microsoft.azure.functions.worker.handler.FunctionLoadRequestHandler.execute(FunctionLoadRequestHandler.java:9)
[2021-06-17T17:10:26.982Z] at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45)
[2021-06-17T17:10:26.983Z] at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92)
[2021-06-17T17:10:26.983Z] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[2021-06-17T17:10:26.983Z] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[2021-06-17T17:10:26.983Z] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[2021-06-17T17:10:26.983Z] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[2021-06-17T17:10:26.983Z] at java.base/java.lang.Thread.run(Thread.java:829)
[2021-06-17T17:10:26.983Z] .
[2021-06-17T17:10:31.849Z] Host lock lease acquired by instance ID '00000000000000000000000001758684'.
But when I run ./mvnw spring-boot:run
, only the Hello.apply()
method works.但是当我运行
./mvnw spring-boot:run
时,只有Hello.apply()
方法有效。 Is this an Azure Dependencies issue?这是 Azure 依赖项问题吗?
Here is my code/structure:这是我的代码/结构:
Project's structure项目结构
src/main
├── azure
│ ├── host.json
│ └── local.settings.json
├── java
│ └── com
│ └── example
│ └── app
│ ├── ExampleApplication.java
│ └── modules
│ ├── HelloHandler.java
│ └── Hello.java
└── resources
└── config
└── application.yml
pom.xml (only the changes I made) pom.xml (仅我所做的更改)
...
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-azure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-function-webflux</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
...
</dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<version>1.12.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
...
</build>
ExampleApplication.java ExampleApplication.java
package com.example.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ExampleApplication {
public static void main(String[] args) {
SpringApplication.run(ExampleApplication.class, args);
}
}
HelloHandler.java HelloHandler.java
package com.example.app.modules;
import com.microsoft.azure.functions.*;
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.HttpTrigger;
import org.springframework.cloud.function.adapter.azure.FunctionInvoker;
import java.util.Optional;
public class HelloHandler extends FunctionInvoker<String, String> {
@FunctionName("Hello")
public HttpResponseMessage execute(
@HttpTrigger(
name = "request",
methods = {HttpMethod.GET},
authLevel = AuthorizationLevel.ANONYMOUS,
route = "hello"
) HttpRequestMessage<Optional<String>> request, ExecutionContext context
) {
String message = request.getQueryParameters().get("message");
return request
.createResponseBuilder(HttpStatus.OK)
.body(handleRequest(message, context))
.header("Content-Type", "application/json")
.build();
}
}
Hello.java你好.java
package com.example.app.modules;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import java.util.function.Function;
@Component
public class Hello implements Function<Mono<String>, Mono<String>> {
@Override
public Mono<String> apply(Mono<String> mono) {
return mono.map(string -> "Your message was: " + string);
}
}
Great to hear that you got it working.很高兴听到你成功了。 According to your comment, did you put spring-boot-maven-plugin at the end of the pom.xml as follows?
根据您的评论,您是否将 spring-boot-maven-plugin 放在 pom.xml 的末尾,如下所示?
<build>
<plugins>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<version>1.12.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- OP put spring-boot-maven-plugin at the end -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
...
</build>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.