我想为 archetype-metadata.xml 中的 requiredProperty 设置一个默认值,以便它基于从命令行传递的另一个属性。说
<requiredProperty key="customProperty">
<defaultValue>${artifactId.toUpperCase()}</defaultValue>
</requiredProperty>
Run Code Online (Sandbox Code Playgroud)
但是,当我使用生成的原型生成新项目时,不是项目的 artifactId 被大写,而是原型的 artifactId。而当我将其更改为
<requiredProperty key="customProperty">
<defaultValue>${artifactId}</defaultValue>
</requiredProperty>
Run Code Online (Sandbox Code Playgroud)
我得到了项目的 artifactId,正如人们所期望的那样。
有没有办法根据另一个属性的值为自定义属性分配默认值?
注意:这仅在交互模式下发生。
mvn -B archetype:generate -DartifactId=archet -DgroupId=com.example -Dversion=1.0-SNAPSHOT -DarchetypeArtifactId=maven-archetype-archetype
Run Code Online (Sandbox Code Playgroud)
由于某种原因,archetype.xml 被生成。这是我的理解,它是一种旧格式。用 archetype-metadata.xml 替换它(为了示例而最小化):
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor name="basic">
<requiredProperties>
<requiredProperty key="customPropertyUppercased">
<defaultValue>${artifactId.toUpperCase()}</defaultValue>
</requiredProperty>
<requiredProperty key="customProperty">
<defaultValue>${artifactId}</defaultValue>
</requiredProperty>
<!--JUnit version to use in generated project-->
<requiredProperty key="junit-version">
<defaultValue>4.12</defaultValue>
</requiredProperty>
</requiredProperties>
<fileSets>
<fileSet filtered="true" packaged="true">
<directory>src/main/java</directory>
</fileSet>
<fileSet filtered="true" packaged="true">
<directory>src/test/java</directory>
</fileSet>
</fileSets>
</archetype-descriptor>
Run Code Online (Sandbox Code Playgroud)
一个模板在 ./src/main/resources/archetype-resources/src/main/java/App.java:
package ${groupId}.${artifactId};
/**
${customPropertyUppercased}
${customProperty}
*/ …Run Code Online (Sandbox Code Playgroud) Spring Boot 中是否有任何属性可用于配置 @Autowired WebTestClient?例如,如何在 WebTestClient 上设置 servlet 上下文路径(或只是一些基本路径)?
以下是我的 Web 测试现在的配置方式:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class MyTestClass{
@Autowired
private WebTestClient cl;
//the rest of it
}
Run Code Online (Sandbox Code Playgroud)
换句话说,Spring Boot 相当于什么
WebTestClient client = WebTestClient.bindToServer()
.baseUrl("http://localhost:<random port>/myServletContext").build();
Run Code Online (Sandbox Code Playgroud)
我在文档中没有找到任何有用的东西:https : //docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
我需要将以下 yaml 字典转换为逗号分隔的 key=value 对列表
nodes:
node1: 192.168.56.11
node2: 192.168.56.12
Run Code Online (Sandbox Code Playgroud)
所以它变成了
node1=192.168.56.11,node2=192.168.56.12
Run Code Online (Sandbox Code Playgroud)
在 Python 中,我会使用简单的列表理解来完成此操作,然后加入列表:
','.join([ k+'='+v for k,v in nodes.items()])
Run Code Online (Sandbox Code Playgroud)
不过,我不知道如何在 Ansible 模板中优雅地做到这一点。for当然,我可以用循环来做到这一点,但它会留下尾随逗号。迄今为止我最好的镜头:
{% for k,v in nodes.items() %}{{k}}={{v}}{% if not loop.last %},{% endif %}{% endfor %}
Run Code Online (Sandbox Code Playgroud)
我是否忽略了什么?