java - 如何使用配置文件运行 gradle?重复 key : spring

标签 java spring gradle profile

我在 application.yml 中有以下内容:

spring:
  jpa:
    generate-ddl: false
    hibernate:
      ddl-auto: none
      dialect: org.hibernate.dialect.SQLServer2012Dialect
  profiles:
    active: @activeProfiles@
   ...
  spring:
    profiles: test
  datasource:
     url: jdbc:h2://localhost:1433;database=testdb
     username: sa
     password:

我像这样开始应用程序:

gradle bootRun -Pspring.profiles.active=test

我看到以下错误:

:common-classes:compileJava UP-TO-DATE                                         
:common-classes:processResources UP-TO-DATE      
:common-classes:classes UP-TO-DATE      
:common-classes:jar UP-TO-DATE      
:compileJava UP-TO-DATE                                                        
:processResources UP-TO-DATE      
:classes UP-TO-DATE      
:findMainClass                 
:bootRun                                                                       
15:45:12.450 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSet
15:45:12.452 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSet
, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
15:45:12.453 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUr
15:45:12.642 [restartedMain] DEBUG org.springframework.boot.logging.ClasspathLog
15:45:12.644 [restartedMain] ERROR org.springframework.boot.SpringApplication -
org.yaml.snakeyaml.parser.ParserException: while parsing MappingNode
 in 'reader', line 70, column 1:
    spring:
    ^
Duplicate key: spring
 in 'reader', line 82, column 14:
    password:
             ^

        at org.springframework.beans.factory.config.YamlProcessor$StrictMapAppen
        at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.const
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseCo
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(Base
        at org.yaml.snakeyaml.constructor.BaseConstructor.getData(BaseConstructo
        at org.yaml.snakeyaml.Yaml$1.next(Yaml.java:471)
        at org.springframework.beans.factory.config.YamlProcessor.process(YamlPr
        at org.springframework.beans.factory.config.YamlProcessor.process(YamlPr
        at org.springframework.boot.env.YamlPropertySourceLoader$Processor.proce
        at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlProper
        at org.springframework.boot.env.PropertySourcesLoader.load(PropertySourc
        at org.springframework.boot.context.config.ConfigFileApplicationListener
        at org.springframework.boot.context.config.ConfigFileApplicationListener
        at org.springframework.boot.context.config.ConfigFileApplicationListener
        at org.springframework.boot.context.config.ConfigFileApplicationListener
        at org.springframework.boot.context.config.ConfigFileApplicationListener
        at org.springfk.boot.context.config.ConfigFileApplicationListener.onAppl
        at org.springframework.boot.context.config.ConfigFileApplicationListener
        at org.springframework.context.event.SimpleApplicationEventMulticaster.i
        at org.springframework.context.event.SimpleApplicationEventMulticaster.m
        at org.springframework.context.event.SimpleApplicationEventMulticaster.m
        at org.springframework.boot.context.event.EventPublishingRunListener.env
        at org.springframework.boot.SpringApplicationRunListeners.environmentPre
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringA
        at org.springframework.boot.SpringApplication.run(SpringApplication.java
        at org.springframework.boot.SpringApplication.run(SpringApplication.java
        at org.springframework.boot.SpringApplication.run(SpringApplication.java
        at com.finvale.MarketplaceApplication.main(MarketplaceApplication.java:1
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.devtools.restart.RestartLauncher.run(Restart

我做错了什么?

最佳答案

您已在配置中声明了 spring 两次:

spring:
  ...
  spring:
     profiles: test

尽管它只需声明一次,如下所示:

spring:
   ...
   profiles: test

只需删除 profiles: 之前的 spring:

关于java - 如何使用配置文件运行 gradle?重复 key : spring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44285247/

相关文章:

java - 无法在rest api中使用InputStream上传多个文件

android - 如何在Android Gradle项目的项目配置阶段之前定义ANDROID_HOME?

java - 管理 EJB 项目中的 hibernate 实体

java - 为什么我的光标在 ListView 中不起作用?

java - 改造将自定义 header 添加为 token - java

java - Spring 4 中 websockets 的动态消息映射

java - 如何减少在 Spring 中攻击内存中密码的表面积?

java - 在 Spring MVC 框架中不使用 MessageSourceAware 访问 MessageSource 的方法

android - 如何将外部库依赖项添加到我的库中?

gradle - 未从环境中获取Gradle包装器经过身份验证的下载凭据