【发布时间】:2019-07-05 01:50:58
【问题描述】:
我们正在使用jooq 生成代码来查询我们的数据库。为了让jooq 运行,我们使用如下环境变量提供配置:
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>${jooq.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<jdbc>
<driver>org.postgresql.Driver</driver>
<url>${DB_URL}</url>
<user>${DB_USER}</user>
<password>${DB_PASSWORD}</password>
</jdbc>
<generator>
<name>org.jooq.codegen.JavaGenerator</name>
<database>
<name>org.jooq.meta.postgres.PostgresDatabase</name>
<includes>.*</includes>
<excludes />
<dateAsTimestamp>true</dateAsTimestamp>
<inputSchema>myDb</inputSchema>
</database>
<generate>
<deprecated>false</deprecated>
<instanceFields>true</instanceFields>
</generate>
<target>
<packageName>com.myapp.jooq</packageName>
<directory>target/generated-sources/jooq-postgres</directory>
</target>
</generator>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
</dependencies>
</plugin>
为了设置这些属性DB_URL、DB_USER、DB_PASSWORD,我们使用vault-maven-plugin,它在 maven 生命周期中的 jooq 之前执行。这是我们使用的配置:
<plugin>
<groupId>com.deciphernow</groupId>
<artifactId>vault-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>pull</id>
<phase>initialize</phase>
<goals>
<goal>pull</goal>
</goals>
<configuration>
<servers>
<server>
<url>http://my.hostedvault.net:8200</url>
<token>myTokenHere</token>
<paths>
<path>
<name>secret/myApp</name>
<mappings>
<mapping>
<key>spring.datasource.username</key>
<property>DB_USER</property>
</mapping>
<mapping>
<key>spring.datasource.password</key>
<property>DB_PASSWORD</property>
</mapping>
<mapping>
<key>spring.datasource.url</key>
<property>DB_URL</property>
</mapping>
</mappings>
</path>
</paths>
</server>
</servers>
</configuration>
</execution>
</executions>
</plugin>
这运行得很好,但是当我们将插件更改为 localhost:8200 时,它总是返回 404 错误:
[错误] 无法在项目 myApp 上执行目标 com.deciphernow:vault-maven-plugin:1.0.0:pull (pull):抛出异常。 Vault 以 HTTP 状态代码响应:404 -> [Help 1]
这仅发生在 vault-maven-plugin 中使用的 localhost 保险库中。所以,这看起来像是 maven 插件上的一个错误(我确认我的 localhost vault 工作属性和 spring-boot 可以毫无问题地从中提取)。知道如何为 Jooq 提供存储在保险库中的凭据属性吗?
【问题讨论】:
标签: java spring-boot jooq hashicorp-vault