ローカル環境では一切問題がないが、AWS Lambda 上で動かすと下記エラーが発生した。
環境
Java: java 11 corretto
Micronaut: 2.3.2 / 2.4.4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
Error starting Micronaut container: Bean definition [service.SomeService] could not be loaded: Error instantiating bean of type [service.SomeService]: service.SomeService: com.amazonaws.serverless.exceptions.ContainerInitializationException com.amazonaws.serverless.exceptions.ContainerInitializationException: Error starting Micronaut container: Bean definition [service.SomeService] could not be loaded: Error instantiating bean of type [service.SomeService]: service.SomeService at io.micronaut.function.aws.proxy.MicronautLambdaContainerHandler.initialize(MicronautLambdaContainerHandler.java:254) at io.micronaut.function.aws.proxy.MicronautLambdaContainerHandler.<init>(MicronautLambdaContainerHandler.java:164) at io.micronaut.function.aws.proxy.MicronautLambdaContainerHandler.<init>(MicronautLambdaContainerHandler.java:118) at io.micronaut.function.aws.proxy.MicronautLambdaHandler.<init>(MicronautLambdaHandler.java:54) at MyLambdaHandler.<init>(MyLambdaHandler.groovy:22) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source) Caused by: io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [service.SomeService] could not be loaded: Error instantiating bean of type [service.SomeService]: service.SomeService at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1549) at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:220) at io.micronaut.context.DefaultBeanContext.readAllBeanDefinitionClasses(DefaultBeanContext.java:2812) at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:233) at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:166) at io.micronaut.function.aws.proxy.MicronautLambdaContainerHandler.initialize(MicronautLambdaContainerHandler.java:250) ... 8 more Caused by: io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type [service.SomeService]: service.SomeService at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1927) at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2679) at io.micronaut.context.DefaultBeanContext.loadContextScopeBean(DefaultBeanContext.java:2215) at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1543) ... 13 more Caused by: java.lang.InstantiationError: service.SomeService at service.$SomeServiceDefinition.build(Unknown Source) at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1898) ... 16 more |
エラーとなっているサービスは、GormServiceのクラス。
原因は、@Service annotation を使っていたサービスで一部実装部分があったため、abstract class として利用していたのが原因。
@Service を利用する箇所は全て interface を利用し実装部分は普通の class を作成してそこに記載するようにした。