0

我在我的 Spring Cloud Function 项目中定义了一个函数,但是在将函数 ( ScanQrCode) 执行为 AS Lambda 之后,我得到:

2020-07-13 10:19:04.592  INFO 1 --- [           main] lambdainternal.LambdaRTEntry             : Started LambdaRTEntry in 26.357 seconds (JVM running for 27.777)
2020-07-13 10:19:04.653  INFO 1 --- [           main] o.s.c.f.c.c.SimpleFunctionRegistry       : Looking up function 'function' with acceptedOutputTypes: []
2020-07-13 10:19:04.731  INFO 1 --- [           main] o.s.c.f.c.c.SimpleFunctionRegistry       : Looking up function 'consumer' with acceptedOutputTypes: []
2020-07-13 10:19:04.734  INFO 1 --- [           main] o.s.c.f.c.c.SimpleFunctionRegistry       : Looking up function 'supplier' with acceptedOutputTypes: []
2020-07-13 10:19:04.754  INFO 1 --- [           main] o.s.c.f.c.c.SimpleFunctionRegistry       : Looking up function '' with acceptedOutputTypes: []
2020-07-13 10:19:04.811  INFO 1 --- [           main] o.s.c.f.c.c.SimpleFunctionRegistry       : Looking up function '' with acceptedOutputTypes: []
2020-07-13 10:19:04.811  INFO 1 --- [           main] o.s.c.f.c.c.SimpleFunctionRegistry       : Looking up function '' with acceptedOutputTypes: []
No function defined: java.lang.IllegalStateException
java.lang.IllegalStateException: No function defined
    at org.springframework.cloud.function.context.AbstractSpringFunctionAdapterInitializer.apply(AbstractSpringFunctionAdapterInitializer.java:187)
    at org.springframework.cloud.function.adapter.aws.SpringBootRequestHandler.handleRequest(SpringBootRequestHandler.java:51)

这里奇怪的是我已经注释掉了consume,supplierfunction函数......我不知道为什么 Spring 或 AWS Lambda 会考虑它们......

这是我的课程:

Spring Boot 应用程序

@SpringBootApplication
public class FoodhatQrApplication {

    public static void main(String[] args) {
        SpringApplication.run(FoodhatQrApplication.class, args);
    }
        
//  @Bean
//  public Function<String, String> function(){
//      return input -> input;
//  }
//  
//  @Bean
//  public Consumer<String> consume(){
//      return input -> System.out.println("Input: " + input);
//  }
//
//  @Bean
//  public Supplier<String> supply(){
//      return () -> "Hello World";
//  }

}

函数类

@Component
    public class ScanQrCode implements Function<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent>{
    
        @Autowired
        private QrCodeRepository qrCodeRepository;
    
        @Override
        public APIGatewayProxyResponseEvent apply(APIGatewayProxyRequestEvent request) {
              APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent();
              response.setStatusCode(302);
              response.setHeaders(Collections.singletonMap("location" , "http://www.google.de"));
              return response;
    
        }
    
    }

我错过了什么?

4

2 回答 2

0

功能组件扫描添加spring.cloud.function.scan.packages可能会有所帮助。

参考:https ://cloud.spring.io/spring-cloud-function/reference/html/spring-cloud-function.html#_function_component_scan

于 2021-12-17T06:20:07.650 回答
-1

在我们的例子中,您肯定需要将您的函数名称“ScanQrCode”添加到 AWS lambda 环境变量中。FUNCTION_NAME:扫描二维码

于 2020-12-16T14:08:10.680 回答