2017-05-31 63 views
2

我有以下的application.yml内容:如何通过配置文件运行gradle?重复键:春天

spring: 
    jpa: 
    generate-ddl: false 
    hibernate: 
     ddl-auto: none 
     dialect: org.hibernate.dialect.SQLServer2012Dialect 
    profiles: 
    active: @[email protected] 
    ... 
    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 

我是怎么错了?

回答

2

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

spring: 
    ... 
    spring: 
    profiles: test 

尽管它有如下只需进行一次宣称:

spring: 
    ... 
    profiles: test 

只是删除spring:肚里profiles: