我有一个Spring Boot应用程序,并且正在使用Spring Boot Actuator和Micrometer来跟踪有关我的应用程序的指标。我特别关注“ http.server.requests”指标和MAX统计信息:
{
"name": "http.server.requests",
"measurements": [
{
"statistic": "COUNT",
"value": 2
},
{
"statistic": "TOTAL_TIME",
"value": 0.079653001
},
{
"statistic": "MAX",
"value": 0.032696019
}
],
"availableTags": [
{
"tag": "exception",
"values": [
"None"
]
},
{
"tag": "method",
"values": [
"GET"
]
},
{
"tag": "status",
"values": [
"200",
"400"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我认为MAX统计信息是执行一个请求的最长时间(因为我已经发出了两个请求,所以这是对其中一个请求进行较长时间处理的时间)。
每当我通过任何标签过滤指标时,例如 localhost:9090/actuator/metrics?tag=status:200
{
"name": "http.server.requests",
"measurements": [
{
"statistic": "COUNT",
"value": 1
},
{
"statistic": "TOTAL_TIME",
"value": 0.029653001
},
{
"statistic": …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的 Spring Boot 应用程序,它使用 Flyway 进行数据库迁移。我想在迁移开始之前使用 Spring 配置类以编程方式设置 Flyway 占位符。
我要做的是:
@Configuration
public class FlywayConfiguration {
@Autowired
private Flyway flyway;
@Value("${threedsserver.db.tableSpaces.data:pg_default}")
private String tablespaceData;
@Value("${threedsserver.db.tableSpaces.index:pg_default}")
private String tablespaceIndex;
@Value("${threedsserver.db.tableSpaces.lob:pg_default}")
private String tablespaceLob;
@PostConstruct
void setFlywayPlaceholders() {
Map<String, String> placeholders = flyway.getPlaceholders();
placeholders.put("tablespace_data", tablespaceData);
placeholders.put("tablespace_index", tablespaceIndex);
placeholders.put("tablespace_lob", tablespaceLob);
flyway.setPlaceholders(placeholders);
}
}
Run Code Online (Sandbox Code Playgroud)
然后在我的迁移脚本中我使用${tablespace_data}属性。迁移失败:
No value provided for placeholder expressions: ${tablespace_data}
Run Code Online (Sandbox Code Playgroud)
我想迁移在处理配置文件之前就开始了。如何解决这个问题?我不想使用 application.properties 来设置飞行路线占位符,但所有其他属性,如spring.flyway.user、等都spring.flyway.password希望由 application.properties 设置。
如何在每次测试执行后使用 Junit5 和 Spring Boot 清除应用程序上下文?我希望在测试中创建的所有 bean 在执行后都被销毁,因为我在多个测试中创建了相同的 bean。我不想为所有测试使用一个配置类,而是每个测试都有一个配置类,如下所示。
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = MyTest.ContextConfiguration.class)
public class MyTest{
...
public static class ContextConfiguration {
// beans defined here...
}
}
Run Code Online (Sandbox Code Playgroud)
Putting@DirtiesContext(classMode = BEFORE_CLASS)不适用于 Junit5。