我正在尝试使用Mac中的Gradle创建一个简单的Spring应用程序。在gradle bootRun上,我得到以下错误:
失败:生成失败,出现异常。
引发的异常: 2015-08-23 01:37:57.989警告6186 -主ationConfigEmbeddedWebApplicationContext :上下文初始化过程中遇到的异常-取消刷新尝试 org.springframework.beans.factory.BeanCreationException:错误创建bean名'embeddedServletContainerCustomizerBeanPostProcessor':失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:错误创建bean的名称'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration':失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:错误创建bean与名称'org.springframework.cache.annotation.ProxyCachingConfiguration':的依赖关系失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动更新的方法: org.springframework.cache.annotation.AbstractCachingConfiguration.setConfigurers(java.util.Collection);嵌套异常是org.springframework.beans.factory.BeanCreationException:错误,创建bean时名称为'org.springframework.cloud.aws.cache.config.annotation.ElastiCacheCachingConfiguration':,自动注入依赖项失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:不能自动更新字段:私有org.springframework.cloud.aws.core.env.stack.ListableStackResourceFactory org.springframework.cloud.aws.cache.config.annotation.ElastiCacheCachingConfiguration.stackResourceFactory;嵌套异常是org.springframework.beans.factory.BeanCreationException:错误,通过工厂方法创建名为“stackResourceRegistryFactoryBean”的类org.springframework.cloud.aws.context.config.annotation.ContextStackConfiguration: bean实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean:工厂方法'stackResourceRegistryFactoryBean‘抛出的异常;嵌套异常是java.lang.IllegalArgumentException:没有在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)的org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)上定义的有效实例id
build.gradle如下所示:
buildscript {
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.0.BUILD-SNAPSHOT")
classpath("io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE")
}
}
apply plugin: 'java'
//apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: "io.spring.dependency-management"
//sourceCompatibility = 1.5
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart',
'Implementation-Version': version
}
baseName = 'myApp'
version = '0.0.1-SNAPSHOT'
}
repositories {
//mavenCentral()
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
maven { url "http://repo.spring.io/release/" }
}
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-aws:1.0.2.RELEASE'
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework:spring-jdbc")
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.springframework.cloud:spring-cloud-starter-aws")
compile("org.springframework.cloud:spring-cloud-aws-jdbc")
compile("org.springframework.boot:spring-boot-starter-undertow")
compile("postgresql:postgresql:9.0-801.jdbc4")
testCompile("org.springframework.boot:spring-boot-starter-test")
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
这里有什么帮助吗?
发布于 2015-08-23 17:10:30
导致异常的原因是配置文件中没有定义EC2环境配置。因为您是在本地机器上运行这个应用程序,所以我假设您不需要它。
溶液
从gradle文件中删除下面的内容,看看是否一切正常。
compile("org.springframework.cloud:spring-cloud-starter-aws")
compile("org.springframework.cloud:spring-cloud-aws-jdbc")
上述依赖项仅适用于设计为在EC2环境中运行的spring应用程序。
希望这能有所帮助。
发布于 2018-03-19 03:29:12
内部src/main/resources
打开文件application.properties
并更改端口(将端口num设置为行),添加以下行:server.port=1337
对我来说也一样。
最后输入:./gradlew bootRun
https://stackoverflow.com/questions/32164882
复制