Aws Lambda-“ errorMessage”:“没有名为'entityManagerFactory'的bean”

时间:2018-10-07 22:42:23

标签: java spring spring-boot gradle aws-lambda

我的应用程序正在使用Spring Boot +批处理+ gradle + mssql + aws Lambda。我将罐子上传到s3存储桶中,并测试了lambda功能  “ errorMessage”:“没有可用的名为'entityManagerFactory'的bean”,   “ errorType”:“ org.springframework.beans.factory.NoSuchBeanDefinitionException”。 应用程序在本地运行良好,尚未设置AWS Cloud RDBMS,我想知道这是错误的原因是因为云中不存在DATABASE和TABLES。 有任何建议专家吗?

filter_update

编辑-build.gradle

"cause": {
        "errorMessage": "No bean named 'entityManagerFactory' available",
        "errorType": "org.springframework.beans.factory.NoSuchBeanDefinitionException",
        "stackTrace": [
          "org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:685)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1210)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)",
          "org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:367)",
          "org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110)",
          "org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:625)",
          "org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:444)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)",
          "org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:312)",
          "org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:131)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1602)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1354)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)",
          "org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)",
          "org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)",
          "org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135)",
          "org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)",
          "org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818)",
          "org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724)",
          "org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1267)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1124)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)",
          "org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)",
          "org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)",
          "org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135)",
          "org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)",
          "org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:583)",
          "org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)",
          "org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1341)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)",
          "org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)",
          "org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)",
          "org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)",
          "org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)",
          "org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135)",
          "org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)",
          "org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:583)",
          "org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)",
          "org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1341)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572)",
          "org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)",
          "org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)",
          "org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)",
          "org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759)",
          "org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)",
          "org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)",
          "org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)",
          "org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398)",
          "org.springframework.boot.SpringApplication.run(SpringApplication.java:330)",
          "org.springframework.boot.SpringApplication.run(SpringApplication.java:1258)",
          "org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)",
          "com.myapp.Main.startApp(Main.java:60)",
          "com.myapp.MyHandler.handleRequest(MyHandler.java:13)",
          "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)"
        ]

application.properties

             buildscript {
             ext {
                springBootVersion = '2.0.1.RELEASE'
            }
            repositories {
                mavenCentral()
            }
            dependencies {
                classpath("org.springframework.boot:spring-boot-gradle 
                plugin:${springBootVersion}")       
            }
           }
           apply plugin: 'java'
           apply plugin: 'eclipse'
           apply plugin: 'org.springframework.boot'
           apply plugin: 'application'
           mainClassName ="com.myapp.MyHandler"

           bootJar{
             mainClassName ='com.myapp.MyHandler.MyHandler'
            } 
        sourceCompatibility = 1.8
        targetCompatibility = 1.8

        repositories {
            mavenCentral()
        }
        dependencies {
            compile 'com.microsoft.sqlserver:mssql-jdbc:6.1.0.jre8'
            compile 'org.springframework.batch:spring-batch-core:3.0.1.RELEASE'
            compile 'org.springframework.boot:spring-boot-starter-batch:2.0.4.RELEASE'
            compile 'org.springframework.boot:spring-boot-starter-data-jpa:2.0.4.RELEASE'
            compile 'com.google.code.gson:gson:2.8.2'   
            compile 'com.amazonaws:aws-lambda-java-core:1.2.0'
            compile 'com.amazonaws:aws-lambda-java-events:2.1.0'
            compile 'org.springframework.boot:spring-boot-maven-plugin:2.0.5.RELEASE'
            compile('org.springframework.boot:spring-boot-starter-data-jpa:2.0.4.RELEASE'){
    exclude group: 'org.javassist', module: 'javassist'
}
           compile 'org.javassist:javassist:3.22.0-GA'
        }

        task fatJar(type: Jar) {
            manifest {
                attributes 'Main-Class': 'com.myapp.MyHandler'
            }
           fileMode = 0755

            baseName = 'all-in-one-jar'
            from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
            with jar
        }

主班

spring.jpa.database-platform=org.hibernate.dialect.SQLServerDialect
    spring.datasource.url=jdbc:sqlserver://localhost\\sqlexpress:1433;databaseName=ABC
    spring.datasource.username=myName
    spring.datasource.password=myPassword
    spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
    spring.jpa.hibernate.ddl-auto =none

1 个答案:

答案 0 :(得分:0)

我通过升级Javassist版本解决了相同的问题。 更新Javassist时,我从工件“ spring-boot-starter-data-jpa”中排除了旧版本的Javassist。

对于Gradle Project更新build.gradle,如下所示:

compile('org.springframework.boot:spring-boot-starter-data-jpa:2.0.4.RELEASE'){
        exclude group: 'org.javassist', module: 'javassist'
    }
compile 'org.javassist:javassist:3.22.0-GA'

对于Maven项目,更新pom.xml,如下所示:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>javassist</artifactId>
            <groupId>org.javassist</groupId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.22.0-GA</version>
    <scope>runtime</scope>
</dependency>