小编Nir*_*jan的帖子

Micrometer 在 OpenTelemetry 项目中适合什么位置

随着 OpenTelemetry 试图成为应用程序/服务可观察性的事实上的标准,Micrometer 适合在哪里?Micrometer网站声称它是SLF4J的metrics,但这不是与OpenTelemetry的Metrics API矛盾吗?我想知道 OpenTelemetry 的 Metric API 是否应该代表 SLF4J,而 Micrometer 是否应该代表 Log4J 之类的实现。

如果有人能帮助我澄清这一点,我将不胜感激。

micrometer open-telemetry

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

ConcurrentHashMap putIfAbsent()返回null

以下程序正在打印NULL.我无法理解为什么.

public class ConcurrentHashMapTest {
    public static final ConcurrentMap<String, String> map = new ConcurrentHashMap<>(5, 0.9f, 2);

    public static void main(String[] args) {
        map.putIfAbsent("key 1", "value 1");
        map.putIfAbsent("key 2", "value 2");

        String value = get("key 3");
        System.out.println("value for key 3 --> " + value);
    }

    private static String get(final String key) {
        return map.putIfAbsent(key, "value 3");
    }
}
Run Code Online (Sandbox Code Playgroud)

有人能帮我理解这种行为吗?

java concurrenthashmap

17
推荐指数
4
解决办法
1万
查看次数

如何在Spring中定义String数组的bean(使用XML配置)

我正在尝试定义类型的Spring bean,String[]现在能够找到一种方法.示例程序如下所示:

@Component("sampleClass")
public class SampleClass {
    @Value("#{someArrayId}")
    private String[] someArray;

    public void doWithArray() {
        System.out.println(Arrays.toString(someArray));
    }
}
Run Code Online (Sandbox Code Playgroud)

Spring XML配置

<context:annotation-config />
<context:component-scan base-package="com.demo.spring" />

<util:list id="someArrayId">
    <array>
        <value>Tiger</value>
        <value>Lion</value>
    </array>
</util:list>
Run Code Online (Sandbox Code Playgroud)

当我运行该程序时,我得到以下异常:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sampleClass': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String[] com.demo.spring.SampleClass.someArray; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.util.ArrayList' to required type 'java.lang.String[]'; nested exception is …
Run Code Online (Sandbox Code Playgroud)

java spring

12
推荐指数
3
解决办法
3万
查看次数

从阵列中删除元素的JSON Patch格式是什么?

我有以下JSON文档,我想从中删除"roles"字段的数组值中的"roleId2"元素:

{
  "id" : 12345,
  "firstName": "SomeFirstName",
  "lastName": "SomeLastName",
  "roles":["roleId1", "roleId2", "roleId3"]
}
Run Code Online (Sandbox Code Playgroud)

如何编写JSON补丁文档来删除该元素?以下表达式是否有效?

{"op": "remove", "path":"/roles", "value": "roleId2"}
Run Code Online (Sandbox Code Playgroud)

或者,它应该是这样的(因为文档中的"角色"值是一个数组)?

{"op": "remove", "path":"/roles", "value": ["roleId2"]}
Run Code Online (Sandbox Code Playgroud)

从阅读RFC 6902,我不清楚哪一个 - 如果 - 是正确的.RFC提到了以下行为,但我不确定它是否与此相关.

如果从数组中删除元素,则指定索引上方的任何元素都会向左移动一个位置.

json-patch

11
推荐指数
2
解决办法
5798
查看次数

如何在SnakeYaml中解析部分YAML文件

我是YAML的新手并且解析了一个YAML配置文件,如下所示:

applications:
  authentication:
    service-version: 2.0
    service-url: https://myapp.corp/auth
    app-env: DEV
    timeout-in-ms: 5000
    enable-log: true

  service1:
    enable-log: true
    auth-required: true
    app-env: DEV
    timeout-in-ms: 5000
    service-url: https://myapp.corp/service1
    service-name: SomeService1
    service-version: 1.1
    service-namespace: http://myapp.corp/ns/service1

  service2:
    enable-log: true
    auth-required: true
    app-env: DEV
    timeout-in-ms: 5000
    service-url: https://myapp.corp/service2
    service-name: SomeService2
    service-version: 2.0
    service-namespace: http://myapp.corp/ns/service2
Run Code Online (Sandbox Code Playgroud)

我必须解析以下Map结构

+==================================+
| Key              |               |
+==================================+
| authentication   | AuthConfig    |
+----------------------------------+
| service1         | ServiceConfig |
+----------------------------------+
| service2         | ServiceConfig |
+----------------------------------+
Run Code Online (Sandbox Code Playgroud)

AuthConfig并且ServiceConfig是我们系统中的自定义对象.

有人可以提供一些提示怎么做?

java yaml snakeyaml

10
推荐指数
1
解决办法
8870
查看次数

Gradle中的超级POM,父POM类型的层次结构管理

我们目前正在使用Maven作为构建工具,并且有一个指令要迁移到Gradle.我们目前的设置是:

  1. 我们有一个超级POM,它定义了所有第三方依赖项,各种插件,分发管理URL以及此POM上传到我们的发行版repo.
  2. 我们有一个聚合器POM,它使用这个超级POM作为父级并聚合多个子模块.
  3. 我们在聚合器POM中定义了几个配置文件来构建组件.

我的问题是,在Gradle中完成所有这些操作的最佳方法是什么.如何在单个Gradle配置中定义所有第三方依赖项并在其他位置使用它.

我是Gradle的新手,所以这听起来可能是一个非常愚蠢的问题.但我要求所有人提供一些帮助和指导.

gradle

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

杰克逊2支持版本控制

有谁知道Jackson2是否支持版本控制; 类似于GSON @Since@Until注释的东西?

jackson

8
推荐指数
2
解决办法
3850
查看次数

Java - 在字符串中查找第一个重复字符的最佳方法是什么

我写了下面的代码来检测字符串中的第一个重复字符.

public static int detectDuplicate(String source) {
    boolean found = false;
    int index = -1;
    final long start = System.currentTimeMillis();
    final int length = source.length();
    for(int outerIndex = 0; outerIndex < length && !found; outerIndex++) {
        boolean shiftPointer = false;
        for(int innerIndex = outerIndex + 1; innerIndex < length && !shiftPointer; innerIndex++ ) {
            if ( source.charAt(outerIndex) == source.charAt(innerIndex)) {
                found = true;
                index = outerIndex;
            } else {
                shiftPointer = true;
            }
        }
    }
    System.out.println("Time taken --> " + …
Run Code Online (Sandbox Code Playgroud)

java algorithm

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

在Spring Boot中,如何将yml节加载为java.util.Properties

在我的spring boot应用程序中,我具有以下配置:

server:
  host: a.com
  port: 5922
  enable-log: true
Run Code Online (Sandbox Code Playgroud)

我想将以上内容阅读为java.util.Properties。我试着把以下课程:

@ConfigurationProperties(prefix = "server")
public class ServerConfig {
  private Properties serverProps;
  // ... Getter/setter
}
Run Code Online (Sandbox Code Playgroud)

引导配置文件如下所示:

@Configuration
@ComponentScan("com.demo")
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableConfigurationProperties({ServerConfig.class})
@Profile({"dev"})
public class TestAppConfiguration {
}

@EnableAutoConfiguration
@SpringBootApplication
public class TestAppInitializer {
  public static void main(final String[] args) {
    SpringApplication.run(TestAppInitializer.class, args);
  }
}
Run Code Online (Sandbox Code Playgroud)

单元测试班:

@SpringApplicationConfiguration(classes = {TestAppInitializer.class})
@ActiveProfiles("dev")
public class ServerConfigTest extends AbstractTestNGSpringContextTests {
  @Autowired
  private ServerConfig serverConfig;

  @Test
  public void printDetails() {
    logger.debug("ServerConfig.properties --> {}", serverConfig.getProperties()); …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

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

如何从RxJava中的输入流创建Observable字节序列

我是RxJava的新手,因此,问这个问题.我有一个输入流,我必须转换为特定大小的字节数组序列.就像是:

Observable
  .just(inputStream)
  .map(new Func1<InputStream, Chunk>());
Run Code Online (Sandbox Code Playgroud)

Chunk是一个自定义类,包含从流中读取的字节数.有人可以帮我理解如何在RxJava中执行此操作

java rx-java

6
推荐指数
1
解决办法
4214
查看次数