Spring Profile include issue with yaml file

时间:2016-02-12 21:17:29

标签: java spring spring-boot snakeyaml

I'm trying to accomplish when the team sets the websphere profile active that the cloud profile is also activated.

yaml file

RewriteEngine On

<Location />
    AuthType Shibboleth
    ShibUseHeaders On
    ShibRequireSession On
    Require valid-user
    AuthGroupFile /etc/httpd/groups
</Location>

RewriteCond "%{LA-F:REMOTE_USER}" =""
RewriteRule ^/session-ping$ /yoursessiondoesnotexist [PT,L]

<Location /yoursessiondoesnotexist>
    AuthType None
    Require all granted
</Location>

RewriteCond "%{LA-F:REMOTE_USER}" !=""
RewriteRule ^/session-ping$ /ok.html [PT,L]

Alias /ok.html /var/www/ok.html

SetEnvIf Request_URI "^/session-ping$" DONTLOG

CustomLog /dev/stdout ncgl env=!DONTLOG

When I set --- spring: application: name: kicapp output: ansi: enabled: ALWAYS profiles: active: local #server: #context-path: / #port: 8080 #logging: #level: #org.springframework.security: DEBUG --- spring: profiles: local --- spring: profiles: unittest --- spring: profiles: cloud test: loaded --- spring: profiles: websphere include: cloud I receive the following error

Caused by: mapping values are not allowed here in 'reader', line 28, column 12: include: cloud

2 个答案:

答案 0 :(得分:6)

这似乎是对SnakeYAML解析器的限制以及Spring Boot使用它的方式。由于yaml允许在具有---分隔符的单个文件中指定多个不同的文档,因此Spring分离单独文档的方式是spring.profiles键,这个键应该是一个简单的结构而不是不幸的是,这是一个复杂的结构。

一个好的解决方法实际上是通过这种方式将其拆分为多个文件:

带有共同内容的

application.yamlapplication-<profile>具有特定于配置文件的扩展程序,使用此结构键spring.profiles.include将按预期工作。

答案 1 :(得分:2)

根据Biju的回答,如果您想使用---分隔符保留单个文件而不使用单独的配置文件,则可以如下定义spring.profiles.include键:

---
spring:
  profiles: currentProfile
  profiles.include: profileToInclude

这样,解析起来就不会是一个复杂的结构,并且两个键都存在。