我正在使用Spring Boot执行器来获取我的应用程序的信息。
我在pom.xml中添加了Spring Boot执行器依赖项,并在属性文件中添加了以下几行:
info:
app:
name: @project.name@
description: @project.description@
version: @project.version@
Run Code Online (Sandbox Code Playgroud)
我从pom.xml获取值:项目的名称,描述和版本。我还想获得构建时间并将其显示在/info端点上。
有什么建议么?
我是否还应该为此更改pom.xml文件?我尝试使用:
info.app.build-time=@build-time@
Run Code Online (Sandbox Code Playgroud)
但这不起作用。
谢谢
我正在重写一个小的DropWizard应用程序,以在SpringBoot上运行。
我的DW应用程序具有以下有效的日志记录配置:
logging:
level: INFO
appenders:
- type: file
currentLogFilename: /var/log/paas/console.log
archivedLogFilenamePattern: /var/log/paas/console.log-%d.gz
archivedFileCount: 7
loggers:
com.myorg:
level: DEBUG
appenders:
- type: file
currentLogFilename: /var/log/paas/paas.log
archivedLogFilenamePattern: /var/log/paas/paas.log-%d.gz
archivedFileCount: 7
Run Code Online (Sandbox Code Playgroud)
此配置将我的应用程序和控制台消息分成两个单独的日志。
当我尝试使用与SpringBoot相同的配置时,它没有任何效果。我可以使用以下配置将所有内容写入单个日志,但是我确实需要有两个单独的日志:
logging:
level:
org.springframework.web: INFO
com.myorg: DEBUG
file: /var/log/paas/paas.log
Run Code Online (Sandbox Code Playgroud)
LogBack和YAML无法做到这一点吗?还是有其他语法可以给我与DropWizard应用程序相同的结果?
我有mockMVC的问题和用它编写的测试.我的测试失败了.我有两种测试方法:
@Test
public void getPersonsForApiConsumerTest() throws Exception {
mockMvc.perform(get(getUri("/consumers/1/persons")))
.andExpect(status().isOk())
.andExpect(jsonPath("$", hasSize(2)))
.andExpect(jsonPath("$[1].name", is("Ligza")))
.andExpect(jsonPath("$[2].name", is("Vekrir")));
}
@Test
public void getPersonsForApiConsumerMapTest() throws Exception {
mockMvc.perform(get(getUri("/consumers/1/persons/map")))
.andExpect(status().isOk())
.andExpect(jsonPath("$[1].name", is("Verkir")))
.andExpect(jsonPath("$[2].name", is("Ligza")));
}
Run Code Online (Sandbox Code Playgroud)
具有映射的Rest方法:
@RequestMapping(value = "/{consumerId}/persons")
public List<PersonDto> getPersonsForApiConsumer(@PathVariable("consumerId") Integer consumerId) throws IOException {
return apiConsumerService.getPersonsListForApiConsumer(consumerId);
}
@RequestMapping(value = "/{consumerId}/persons/map")
public Map<ApiConsumerPersonRole, List<Person>> getPersonsForApiConsumerMap(@PathVariable("consumerId") Integer consumerId) throws IOException {
return apiConsumerService.getPersonsMapForApiConsumer(consumerId);
}
Run Code Online (Sandbox Code Playgroud)
通过Postman我可以获得这样的数据:
列表:
[
{
"id": 1,
"firstName": "Ligza",
"lastName": "Zetasor",
"role": "REPRESENTATIVE",
"phone": "123123123",
"email": "ligza.zetasor@gmail.com"
},
{
"id": …Run Code Online (Sandbox Code Playgroud) 我希望能够通过指南针在Mongo数据库中编辑一些文档,但是查询仅显示20个最新结果。我怎么能查看超过20个?或者至少查看下20个?
Junit-5测试用例成功地从命令行运行.我正在使用Maven,当我运行使用mvn clean install测试用例成功运行但是当使用IntelliJ运行单个测试用例时,它失败并出现以下错误.
Feb 15, 2018 11:33:41 PM org.junit.jupiter.engine.discovery.JavaElementsResolver resolveMethod
WARNING: Method 'public static java.util.Collection com.softiventure.dtos.junit.parametrized.NestedParametrizedTest$sumTest.parameters()' could not be resolved.
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/LauncherDiscoveryRequest;)V
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:59)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Run Code Online (Sandbox Code Playgroud)
我的示例测试类是:
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@DisplayName("Pass paramters ")
public class ParametrizedJunit5Test {
@DisplayName("Should pass a non-null message to our test method")
@ParameterizedTest
@ValueSource(strings = {"Hello", "World"})
void shouldPassNonNullMessageAsMethodParameter(String …Run Code Online (Sandbox Code Playgroud) 我的代码中有以下日志记录语句。
import org.slf4j.Logger;
public class MySampleClass {
private static final Logger logger = LoggerFactory.getLogger(MySmapleClass.class);
public void mySampleMethod(List<String> userID) {
logger.debug("userRuntimeId =" + userId);
.
.
.
Business Logic
.
.
}
}
Run Code Online (Sandbox Code Playgroud)
这将打印我的日志,如下所示,
2019-02-25 16:27:45,460 | 调试 | [fileTaskExecutor-2] | [a.abc.mySampleApp.handlers.userRecordHandler] | [MY_SAMPLE_APP] | [Vijay-20190225-162738.trigger] | [] | userRuntimeId = 3051aa39-2e0a-11e9-bee3-e7388cjg5le0
我想将日志打印为 JSON。我该怎么做?
我期望的示例 JSON 格式:
{
timestamp="2019-02-25 16:27:45,460" ,
level="DEBUG",
triggerName="fileTaskExecutor-2",
className="a.abc.mySampleApp.handlers.userRecordHandler",
appName="MY_SAMPLE_APP",
userRuntimeId="3051aa39-2e0a-11e9-bee3-e7388cjg5le0"
}
Run Code Online (Sandbox Code Playgroud) 如何为 Map 创建参数捕获器?
我有遵循以下模式的代码:
import java.util.HashMap;
import java.util.Map;
public class CompoundClass {
public CompoundClass (String a, String b){
this.a = a;
this.b = b;
}
public String a;
public String b;
}
public class SubClass {
public void doSomeThingSubClass(Map<String, CompoundClass> mapSb) {
...
}
}
public class Example {
public SubClass sb;
public Example(SubClass sb) {
this.sb = sb;
}
public void doSomeThing () {
Map<String, CompoundClass> mapSb = new HashMap<>();
mapSb.put("x", new CompoundClass("aa","bb"));
sb.doSomeThingSubClass(mapSb);
}
}
Run Code Online (Sandbox Code Playgroud)
我想测试方法 doSomethingSubClass(mapSb) 是否被调用,因此我需要能够检查它被调用的参数。为此,我进行了以下单元测试: …
我正在 spock 框架中编写一个规范类。
@ContextConfiguration(classes = [MyServiceImplementation.class])
class MyServiceSpecification extends Specification {
@Autowired
private MyService myServiceImplementation
def " " {
//code
}
}
Run Code Online (Sandbox Code Playgroud)
该类MyServiceImplementation已注释@Service。我没有使用 XML 配置。MyServiceImpl是接口的实现:MyService。
为什么自动装配的对象为myServiceImplementation空?
我尝试使用ComponentScan,但仍然不起作用。
我想知道是否存在一些方法来禁止SpringBoot Actuator监视特定数据源.
场景: 一个微服务使用3个数据源但是对于某些业务原因,它们是一个数据源,没有必要由Spring Boot Health Indicator监控.
如何禁用某个特定DataSource的监控?
提前谢谢了
Juan Antonio
我看到Intellij中的内置代码覆盖率非常小(仅包括行覆盖,而不是分支覆盖).
使用IntelliJ的推荐代码覆盖库有哪些?
(我曾经在Eclipse中与Jacoco合作过).
java ×5
junit ×3
spring ×3
logback ×2
spring-boot ×2
unit-testing ×2
dropwizard ×1
json ×1
junit5 ×1
logging ×1
maven ×1
mocking ×1
mockito ×1
mockmvc ×1
mongodb ×1
slf4j ×1
spock ×1
spring-mvc ×1
testing ×1
yaml ×1