“ errorMessage”:“没有可用的名为'entityManagerFactory'的bean”

时间:2018-10-09 17:31:40

标签: java spring gradle amazon-s3 aws-lambda

我的应用程序正在使用Spring Boot +批处理+ gradle + mssql + aws Lambda。我将罐子上载到s3存储桶中,并测试了lambda功能是否获得了“ errorMessage”:“没有可用的名为'entityManagerFactory'的bean”,“ errorType”:“ org.springframework.beans.factory.NoSuchBeanDefinitionException”。应用程序在本地运行良好,尚未设置AWS Cloud 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)"
    ]

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'
        } 
    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'
    }

    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 {

0 个答案:

没有答案