小编Jus*_*tas的帖子

如何计算Datadog中日志之间的持续时间?

Splunk 有transaction可以duration在按 id 分组的日志之间生成的命令:

2020-01-01 12:12 event=START id=1
2020-01-01 12:13 event=STOP  id=1
Run Code Online (Sandbox Code Playgroud)

正如它所描述的

如何计算Datadog中事件之间的持续时间?

logging monitoring datadog splunk-query

13
推荐指数
1
解决办法
4621
查看次数

在pg_stat_activity中具有"空闲"状态的持久"COMMIT"查询

如果我查询:

select * from pg_stat_activity where application_name ~ 'example-application';
Run Code Online (Sandbox Code Playgroud)

我得到很多行,状态是idle和查询COMMIT.它们持久耐用,不会消失.一段时间后,我的应用程序达到hibernate.c3p0.max_size(池中的最大JDBC连接数)限制并停止使用数据库.

一些应用程序实现细节在其他SO线程中描述: 线程池中的Guice DAO提供程序 - 查询变为"在转换中空闲"

为什么会这样?如何解决这个问题呢?

java postgresql hibernate connection-pooling guice

12
推荐指数
1
解决办法
3804
查看次数

Spring @Retryable - 如何在调用时记录?

我用compile 'org.springframework.retry:spring-retry:1.2.2.RELEASE'Spring Boot 1.5.9.RELEASE.

配置为重试我的方法,它运作良好:

@Retryable(value = { IOException.class }, maxAttempts = 5, backoff = @Backoff(delay = 500))
public void someMethod(){...}
Run Code Online (Sandbox Code Playgroud)

重试发生时如何输出某些特定消息?

spring spring-retry spring-boot

9
推荐指数
2
解决办法
7000
查看次数

在Spring Boot控制器中反序列化枚举忽略大小写

我有Spring Boot端点,它有枚举作为查询参数:

@GetMapping("/example")
public List<Example> getByEnum(@RequestParam(name = "exampleEnum", required = false) ExampleEnum exampleEnum) {
    // code
}
Run Code Online (Sandbox Code Playgroud)

和枚举类:

public enum ExampleEnum {
    FIRST,
    SECOND,
}
Run Code Online (Sandbox Code Playgroud)

如果我将大写枚举值传递给endpoit,它反序列化很好,但它会抛出小写错误:

java.lang.IllegalArgumentException: No enum constant 
Run Code Online (Sandbox Code Playgroud)

如何在Spring Boot Rest端点中反序列化枚举忽略大小写?

java enums spring spring-boot

6
推荐指数
2
解决办法
4281
查看次数

将 Jersey 1 更新为 Jersey 2 - Guice 配置 - GuiceContainer 和 PackagesResourceConfig 无法解析为类型

我有项目 Guice - Jersey 1.19 项目与依赖项:

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>${version.jersey}</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>${version.jersey}</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>${version.jersey}</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>${version.jersey}</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>${version.jersey}</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>${version.jersey}</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-guice</artifactId>
        <version>${version.jersey}</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我已经用 Jersey 版本 2.22.2 替换了它们:

    <dependency>
        <groupId>com.squarespace.jersey2-guice</groupId>
        <artifactId>jersey2-guice</artifactId>
        <version>0.10</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>${version.jersey}</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>${version.jersey}</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>${version.jersey}</version>
    </dependency>
    <dependency>
        <groupId>com.owlike</groupId>
        <artifactId>genson</artifactId>
        <version>1.4</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我有服务("/rest/*").with(GuiceContainer.class, params); 但目前没有 PackagesResourceConfig 和 GuiceContainer。

public class BootstrapServletModule …
Run Code Online (Sandbox Code Playgroud)

rest servlets jersey guice jersey-2.0

5
推荐指数
0
解决办法
1022
查看次数

Google 登录 GoogleIdToken 后端验证突然失败

我总是在使用 Google 登录时遇到这个问题。我有一个 Android 应用程序,用户连接使用该应用程序向 Google 进行身份验证,然后将 idToken 发送到我的服务器。服务器使用 Google 提供的库 (GoogleIdTokenVerifier) 来验证令牌。

   GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(transport, jsonFactory)
            .setAudience(audience)
            .setIssuer("https://accounts.google.com")
            .build();

    GoogleIdToken idToken = null;

    try {
        idToken = verifier.verify(idTokenString);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (idToken != null) {
        GoogleIdToken.Payload payload = idToken.getPayload();
        String userId = payload.getSubject();
        System.out.println("User ID: " + userId);
        String email = payload.getEmail();
        System.out.println("Emaail:" + email);
        return userId;
    } else {
        System.out.println("Invalid ID token.");
        return null;
    }
Run Code Online (Sandbox Code Playgroud)

这工作了一段时间,然后突然验证开始总是失败。什么也没有变!有任何想法吗?

java android token google-login google-signin

5
推荐指数
1
解决办法
1128
查看次数

ExecutorService - 在方法中创建新实例而不是每个类一个

我应该在每个方法调用中创建新的 ExecutorService 还是每个类使用一个?就性能而言,哪个是首选?

public class NotificationService {

    public void sendNotification(User recipient) {

        ExecutorService notificationsPool = Executors.newFixedThreadPool(10);

        // code

        notificationsPool.shutdown();
    }
}
Run Code Online (Sandbox Code Playgroud)

或者

public class NotificationService {

    ExecutorService notificationsPool = Executors.newFixedThreadPool(10);

    public void sendNotification(User recipient) {

        // code
    }
}
Run Code Online (Sandbox Code Playgroud)

java concurrency multithreading executorservice threadpool

5
推荐指数
1
解决办法
2048
查看次数

为什么组件扫描不适用于 Spring Boot 单元测试?

服务类用@Service又名FooServiceImpl注释,这使其符合自动装配的条件。为什么在单元测试期间这个类没有被拾取和自动装配?@Component

@Service
public class FooServiceImpl implements FooService {
    @Override
    public String reverse(String bar) {
        return new StringBuilder(bar).reverse().toString();
    }
}

@RunWith(SpringRunner.class)
//@SpringBootTest
public class FooServiceTest {
    @Autowired
    private FooService fooService;
    @Test
    public void reverseStringShouldReverseAnyString() {
        String reverse = fooService.reverse("hello");
        assertThat(reverse).isEqualTo("olleh");
    }
}
Run Code Online (Sandbox Code Playgroud)

测试未能加载应用程序上下文,

2018-02-08T10:58:42,385 INFO    Neither @ContextConfiguration nor @ContextHierarchy found for test class [io.github.thenilesh.service.impl.FooServiceTest], using DelegatingSmartContextLoader
2018-02-08T10:58:42,393 INFO    Could not detect default resource locations for test class [io.github.thenilesh.service.impl.FooServiceTest]: no resource found for suffixes {-context.xml}.
2018-02-08T10:58:42,394 INFO …
Run Code Online (Sandbox Code Playgroud)

java spring integration-testing unit-testing spring-boot

5
推荐指数
1
解决办法
2万
查看次数

版本更新到3.34后,Google地图控件按钮太大

Google 于2018年8月13日将Google Maps JavaScript API V3参考更新为v3.34.目前没有发行说明.我注意到我们的网站缩放和地图类型选择按钮比以前大得多.此外,这种变化似乎影响了许多其他网站.控件是默认值,取自Google API.当我改变版本时,v=3.33它们变得像以前一样大小.但是,v=3.33将在几个月内弃用.我应该等待Google修复吗?或者使用v3.34并制作自定义控件?

在此输入图像描述

google-maps google-maps-api-3

5
推荐指数
0
解决办法
2701
查看次数

如何在 MockRestServiceServer 中通过字符串模式期望 requestTo?

我有以下测试:

org.springframework.test.web.client.MockRestServiceServer mockServer
Run Code Online (Sandbox Code Playgroud)

当我使用any(String.class)或确切的 URL运行时,它们运行良好:

mockServer.expect(requestTo(any(String.class)))
.andExpect(method(HttpMethod.GET))
.andRespond(withSuccess("response", MediaType.APPLICATION_JSON));
Run Code Online (Sandbox Code Playgroud)

或者:

mockServer.expect(requestTo("https://exact-example-url.com/path"))
.andExpect(method(HttpMethod.GET))
.andRespond(withSuccess("response", MediaType.APPLICATION_JSON));
Run Code Online (Sandbox Code Playgroud)

我希望通过字符串模式请求避免检查确切的 URL。我可以在Spring MockRestServiceServer上编写自定义匹配器来处理对同一 URI 的多个请求(自动发现)

有没有其他方法可以mockServer.expect(requestTo(".*example.*"))通过 String 模式制作?

java junit mockito spring-boot mockserver

5
推荐指数
1
解决办法
5907
查看次数