我使用 micronaut-function-aws 功能处理了一个简单的 Micronaut AWS lambda 请求。
我注入的服务在 AWS 中运行时似乎没有创建。
如果我执行整个 groovy 脚本函数处理程序并使用 @Field @Singleton TestService testService 它在本地运行时似乎工作正常。
知道我做错了什么吗?
服务:
package testtest
import groovy.transform.CompileStatic
@CompileStatic
@Singleton
class TestService {
String test = "Test"
}
处理程序:
package testtest
import com.amazonaws.services.lambda.runtime.Context
import io.micronaut.function.aws.MicronautRequestStreamHandler
import javax.inject.Inject
class TestHandler extends MicronautRequestStreamHandler {
@Inject TestService testService
@Override
protected void execute(InputStream input, OutputStream output, Context context) throws IOException {
output << testService.test
}
}
来自 AWS lambda 的堆栈跟踪
Cannot get property 'test' on null object: java.lang.NullPointerException
java.lang.NullPointerException: Cannot get property 'test' on null object
at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60)
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:190)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:304)
at testtest.TestHandler.execute(TestHandler.groovy:14)
at testtest.TestHandler.execute(TestHandler.groovy)
at io.micronaut.function.aws.MicronautRequestStreamHandler.handleRequest(MicronautRequestStreamHandler.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)