Aws Lambda - «errorMessage»: «Нет доступных бинов с именем entityManagerFactory» - PullRequest
0 голосов
/ 08 октября 2018

Мое приложение использует Spring boot + batch + gradle + mssql + aws Lambda.Я загрузил jar в корзину s3 и протестировал лямбда-функционал, получивший сообщение «errorMessage»: «Нет доступных бинов с именем entityManagerFactory», «errorType»: «org.springframework.beans.factory.NoSuchBeanDefinitionException».Приложение работает нормально локально, в облаке AWS RDBMS еще не настроена, мне интересно, это ошибка, потому что DATABASE и TABLES отсутствуют в облаке.Любое предложение экспертов?

"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)"
        ]

Edit-build.gradle

             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
        }

application.properties

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

основной класс

    @SuppressWarnings("PMD")
    @SpringBootApplication
    @EnableAutoConfiguration
    @EnableJpaRepositories(basePackages="com.myapp.repository")
    @ComponentScan("com.myapp")
    @EnableScheduling
    public class BatchMain {

1 Ответ

0 голосов
/ 15 октября 2018

Я исправил ту же проблему, обновив версию Javassist.При обновлении Javassist я исключил старую версию Javassist из артефакта "spring-boot-starter-data-jpa".

Для обновления 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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...