com.amazonaws.services.lambda.invoke.LambdaSerializationException:方法hashCode

时间:2017-07-30 12:41:49

标签: java spring amazon-web-services spring-boot aws-lambda

从spring启动项目调用aws-lambda函数时出现此错误。但是当我运行我的测试时,它会正确响应。 问候。

完整追踪:

  

org.springframework.beans.factory.BeanCreationException:错误   用名称' homeController创建bean&#39 ;:注入自动装配   依赖失败;嵌套异常是   com.amazonaws.services.lambda.invoke.LambdaSerializationException:没有   方法hashCode的LambdaFunction注释   org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)   〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)   〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)   〜[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at   org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)   [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at   org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)   [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at   org.springframework.boot.SpringApplication.run(SpringApplication.java:303)   [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at   org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)   [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at   org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)   [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at   mx.com.dish.dev.drp.monitor.MonitorDRPwebApplication.main(MonitorDRPwebApplication.java:15)   [classes /:na]引起:   com.amazonaws.services.lambda.invoke.LambdaSerializationException:没有   方法hashCode的LambdaFunction注释   com.amazonaws.services.lambda.invoke.LambdaInvokerFactory $ LambdaInvocationHandler.validateInterfaceMethod(LambdaInvokerFactory.java:227)   〜[aws-java-sdk-lambda-1.11.169.jar:na] at   com.amazonaws.services.lambda.invoke.LambdaInvokerFactory $ LambdaInvocationHandler.invoke(LambdaInvokerFactory.java:213)   〜[aws-java-sdk-lambda-1.11.169.jar:na] at   com.sun.proxy。$ Proxy69.hashCode(Unknown Source)〜[na:na] at   java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)   〜[na:1.8.0_131] at   java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:964)   〜[na:1.8.0_131] at   org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.requiresDestruction(PersistenceAnnotationBeanPostProcessor.java:380)   〜[spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.DisposableBeanAdapter.hasApplicableProcessors(DisposableBeanAdapter.java:431)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory.requiresDestruction(AbstractBeanFactory.java:1662)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory.registerDisposableBeanIfNecessary(AbstractBeanFactory.java:1679)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:597)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at   org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)   〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] ... 17常见   框架省略

致电代码:

@ContextConfiguration(classes = {
 LambdaTestConfig.class
})
@RunWith(SpringJUnit4ClassRunner.class)
public class TestMail {

 @Autowired 
 LambaServices service;

 @Test 
 public void testLogin() {
  UserLoginInput login = new UserLoginInput();
  login.setUserName("usuarioPDM");
  login.setPasswordHash(org.apache.commons.codec.digest.DigestUtils.sha256Hex("usrPDM0017#"));
  System.out.println(service.login(login).getOpenIdToken());
 }
}

1 个答案:

答案 0 :(得分:0)

目前使用aws sdk中的注释创建lambda函数,如下所示:

interface LambdaService {
    @LambdaFunction(functionName = "some-lambda-function")
    fun execute(input: Request): Response
}

仅捕获toString()方法的调用,但不捕获hashCode()方法。

Spring将bean存储在地图中,主动使用hashCode()

作为一种解决方法,我建议使用使用aws sdk创建的Lambda Service的具体Holder:

class LambdaServiceHolder(val lambdaService: LambdaService)

然后你只需要创建holder bean而不是service bean

@Configuration
open class LambdaConfiguration {
    @Bean
    open fun lambdaService(): LambdaServiceHolder {
        val awsLambda = AWSLambdaClientBuilder.defaultClient()
        val service = LambdaInvokerFactory.builder().lambdaClient(awsLambda).build(LambdaService::class.java)
        return LambdaServiceHolder(service);
    }
}