我有一个非常简单的Spring Cloud Functions,带有AWS适配器,可以将其作为AWS Lambda运行。可以在Github上找到源代码:https://github.com/codependent/spring-boot-authentication-function
@SpringBootApplication
class SpringBootAuthenticationFunctionApplication {
@Bean
fun kotlinSupplier(): (Credentials) -> AuthenticationResponse {
return {
if (it.user == "jose" && it.password == "MyPassword") {
//HMAC
val algorithm = Algorithm.HMAC256("secret")
val token = JWT.create()
.withIssuer("MicronautAwsAuthenticationFunction")
.withSubject(it.user)
.sign(algorithm)
AuthenticationResponse(token)
} else {
AuthenticationResponse()
}
}
}
}
fun main(args: Array<String>) {
runApplication<SpringBootAuthenticationFunctionApplication>(*args)
}
当我在AWS Lambda上运行此函数时,它将引发NullPointerException。知道怎么了吗?
{
"errorMessage": "java.lang.NullPointerException",
"errorType": "java.lang.NullPointerException",
"stackTrace": [
"org.springframework.cloud.function.context.FunctionalSpringApplication.postProcessApplicationContext(FunctionalSpringApplication.java:102)",
"org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:372)",
"org.springframework.boot.SpringApplication.run(SpringApplication.java:314)",
"org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer.initialize(SpringFunctionInitializer.java:86)",
"org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.initialize(SpringBootStreamHandler.java:55)",
"org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.handleRequest(SpringBootStreamHandler.java:64)",
"sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
"sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)",
"sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
"java.lang.reflect.Method.invoke(Method.java:498)"
]
}
我已将org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler
设置为AWS控制台中处理程序类的值。
完整的CloudWatch日志:
16:12:39.252 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Searching manifests: [jar:file:/var/runtime/lib/LambdaJavaRTEntry-1.0.jar!/META-INF/MANIFEST.MF, jar:file:/var/runtime/lib/aws-lambda-java-core-1.2.0.jar!/META-INF/MANIFEST.MF, file:/var/task/META-INF/MANIFEST.MF]
16:12:39.258 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Searching manifest: jar:file:/var/runtime/lib/LambdaJavaRTEntry-1.0.jar!/META-INF/MANIFEST.MF
16:12:39.259 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Searching manifest: jar:file:/var/runtime/lib/aws-lambda-java-core-1.2.0.jar!/META-INF/MANIFEST.MF
16:12:39.260 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Searching manifest: file:/var/task/META-INF/MANIFEST.MF
16:12:39.261 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Searching manifests: []
16:12:39.261 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Main class: null
START RequestId: 66460dc7-e90b-487c-a022-12c04ab72c7d Version: $LATEST
16:12:39.272 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Initializing: null
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::
2019-03-21 16:12:45.617 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.NullPointerException: null
at org.springframework.cloud.function.context.FunctionalSpringApplication.postProcessApplicationContext(FunctionalSpringApplication.java:102) ~[task/:na]
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:372) ~[task/:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) ~[task/:na]
at org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer.initialize(SpringFunctionInitializer.java:86) [task/:na]
at org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.initialize(SpringBootStreamHandler.java:55) [task/:na]
at org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.handleRequest(SpringBootStreamHandler.java:64) [task/:na]
at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:888) [LambdaSandboxJava-1.0.jar:na]
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:293) [LambdaSandboxJava-1.0.jar:na]
at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64) [LambdaSandboxJava-1.0.jar:na]
at java.lang.Class.forName0(Native Method) [na:1.8.0_181]
at java.lang.Class.forName(Class.java:348) [na:1.8.0_181]
at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:104) [LambdaJavaRTEntry-1.0.jar:na]
java.lang.NullPointerException: java.lang.NullPointerException
java.lang.NullPointerException
at org.springframework.cloud.function.context.FunctionalSpringApplication.postProcessApplicationContext(FunctionalSpringApplication.java:102)
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:372)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer.initialize(SpringFunctionInitializer.java:86)
at org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.initialize(SpringBootStreamHandler.java:55)
at org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.handleRequest(SpringBootStreamHandler.java:64)