Typesafe配置覆盖包含冒号的变量



我使用Typesafe配置来管理我的Flink SQL命令。例如,

source = """
CREATE TABLE kafka_source (
`body` ROW<`log` ROW<`uid` BIGINT, serverts BIGINT, `contentstr` STRING>>
) WITH (
'connector' = 'kafka',
'topic' = 'data-report-stat-old-logtype7',
'properties.bootstrap.servers' = '10.111.135.233:9092',
'properties.group.id' = 'flink-test2',
'json.fail-on-missing-field' = 'false',
'format' = 'json'
)
"""

我的properties.bootstrap.servers是特定于Maven配置文件的,因此我想在Maven pom.xml

中配置它
<profiles>
<profile>
<id>testing</id>
<properties>
<kafka.source.servers>10.111.135.233:9092</kafka.source.servers>
</properties>
</profile>
</profiles>

我想引用并使用Typesafe配置中的属性,

source = """
CREATE TABLE kafka_source (
`body` ROW<`log` ROW<`uid` BIGINT, serverts BIGINT, `contentstr` STRING>>
) WITH (
'connector' = 'kafka',
'topic' = 'data-report-stat-old-logtype7',
'properties.bootstrap.servers' = '"""${kafka.source.servers}"""',
'properties.group.id' = 'flink-test2',
'json.fail-on-missing-field' = 'false',
'format' = 'json'
)
"""

但是,如果我运行mvn clean package -Ptesting,配置被内置到

source = """
CREATE TABLE kafka_source (
`body` ROW<`log` ROW<`uid` BIGINT, serverts BIGINT, `contentstr` STRING>>
) WITH (
'connector' = 'kafka',
'topic' = 'data-report-stat-old-logtype7',
'properties.bootstrap.servers' = '"""10.111.135.233:9092"""',
'properties.group.id' = 'flink-test2',
'json.fail-on-missing-field' = 'false',
'format' = 'json'
)
"""

并且在加载配置时抛出异常,因为10.111.135.233:9092包含::

Expecting close brace } or a comma, got ':' (if you intended ':' to be part of a key or string value, try enclosing the key or value in double quotes

解决这个问题的正确方法是什么?谢谢!

我认为这是typesafe配置的问题。为了解决这个问题,使用application.properties文件代替application.conf

last-n-clicks.generation-ingestion.source=
CREATE TABLE kafka_source ( 
`body` ROW<`log` ROW<`uid` BIGINT, serverts BIGINT, `contentstr` STRING>> 
) WITH ( 
'connector' = 'kafka', 
'topic' = 'data-report-stat-old-logtype7', 
'properties.bootstrap.servers' = '${kafka.source.servers}', 
'properties.group.id' = 'flink-test2', 
'json.fail-on-missing-field' = 'false', 
'format' = 'json' 
)

最新更新