我有一个Kotlin Spring Boot自动配置项目。它有一个带有注释的类@ConfigurationProperties。这将按预期生成属性元数据文件。我想添加一个不是来自@ConfigurationProperties该类的属性。如文档所述,为此,我应该创建自己的additional-spring-configuration-metadata.json文件。
我发现我第一次运行mvn clean package时,会生成元数据,而不会包含来自的信息additional-spring-configuration-metadata.json。第二次运行mvn包(假设我没有清理干净),元数据包含来自additional-spring-configuration-metadata.json
为什么是这样?如何修复它以便每次都首次生成数据?
我的pom在下面:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.redacted.entity.autoconfigure</groupId>
<artifactId>mongo-autoconfiguration</artifactId>
<version>1.0.0</version>
<name>mongo-autoconfiguration</name>
<description>AutoConfiguration for mongo</description>
<properties>
<java.version>1.8</java.version>
<kotlin.version>1.3.50</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId> …Run Code Online (Sandbox Code Playgroud) 我有一个散列,其值是所有数组.我想在这个哈希中查找一个键.如果它存在,我想为数组添加一个值.如果它不存在(hash [key]返回nil),那么我需要创建数组并添加一个值.目前我有这个:
hash[key].push elem unless hash[key].nul?
hash[key] ||= [elem]
Run Code Online (Sandbox Code Playgroud)
这涉及3次查找.我是ruby的新手,所以我相信有更好的方法可以做到这一点.它是什么?
我最初的计划是为hash []设置默认值.然后我可以使用:
hash[key].push elem
Run Code Online (Sandbox Code Playgroud)
不幸的是,如果密钥不存在,那只会更改默认值而不会添加新密钥.