小编Adi*_*ari的帖子

Mono<Void> 和 Mono.empty() 有何不同

据我了解,在 Spring WebFlux 反应器中

Mono<Void>指的是 void Mono

Mono.empty()指的是 void,因为在此之上调用任何内容都会给出空指针。

它们的用法有何不同?

java spring reactor reactive-programming spring-webflux

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

在 mvn spring-boot:run 之前是否需要 mvn clean install

从 Git Repo 中提取现有项目

我尝试使用运行它mvn spring-boot:run,但它给出了错误

然后执行了mvn clean installthen did mvn spring-boot:run,它就开始运行了!

刚才我也是想mvn spring-boot:run执行任务mvn clean install啊!

但是,如何mvn spring-boot:run在编译时考虑最新代码(我的意思是,如果它不这样做install,则不应编译,因此它应该运行过时的 JAR,但它需要新的代码更改并刷新 JAR)

有人可以通过一些线索来解决这个困惑吗!

java maven spring-boot

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

IllegalStateException 主题、分区和模式的订阅是互斥的

需要从 Kafka 主题的特定偏移量获取消息

导致 IllegalStateException 异常卡在assign()

如果我不使用assign(),那么消费者不会执行搜索,因为这是一个惰性操作

实际目的:需要从预先确定的偏移量到结束迭代主题中的消息。该预先确定的偏移量计算为markOffset()

static void fetchMessagesFromMarkedOffset() {
    Consumer<Long, String> consumer = ConsumerCreator.createConsumer();
    consumer.assign(set); // <---- Exception at this place
    map.forEach((k,v) -> {
        consumer.seek(k, v-3);
    });
    ConsumerRecords<Long, String> consumerRecords = consumer.poll(100);
    consumerRecords.forEach(record -> {
        System.out.println("Record Key " + record.key());
        System.out.println("Record value " + record.value());
        System.out.println("Record partition " + record.partition());
        System.out.println("Record offset " + record.offset());
    });
    consumer.close();
}
Run Code Online (Sandbox Code Playgroud)

涉及的其余相关代码

public static Set<TopicPartition> set;
public static Map<TopicPartition, Long> map;

static void markOffset() { …
Run Code Online (Sandbox Code Playgroud)

java apache-kafka microservices kafka-consumer-api

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

默认值为 @Value 处的持续时间

我需要为java.time.Duration类型的实例变量指定默认值

我传递的默认值被读取为字符串,导致 IllegalStateException

我的课

public class Test {
  @Value("${kafka.consumer.commit.interval:5s}")
  private Duration commitInterval;

  .
  .
  .

}
Run Code Online (Sandbox Code Playgroud)

例外:

  Unsatisfied dependency expressed through field 'commitInterval'; 
  nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'java.time.Duration'; 
  nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.time.Duration': no matching editors or conversion strategy found
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

3
推荐指数
1
解决办法
4138
查看次数

为什么将微服务分布式事务模式命名为 SAGA?

我经历了各种SAGA 模式Orchestration、Choreography),建议在分布式事务期间保持微服务中的数据库一致性。

但我无法在上下文中关联字面意思的SAGA

为什么它被命名为SAGA

java design-patterns distributed-transactions saga microservices

3
推荐指数
2
解决办法
820
查看次数

Map.ofEntries 在使用 containsKey() 检查 NULL 键时给出空指针异常

我之前使用 HashMap 从常量映射中获取键。

在传递NULL 键containsKey(),我常常得到FALSE

为了让代码看起来更漂亮,我尝试了 java-8 。因此,我开始使用 Map.ofEntries来构建我的地图,而不是 HashMap

令人惊讶的是,当将空键传递给方法时,我得到了空指针异常containsKey()

String str = null;

Map<String,String> hashMap = new HashMap<>();
hashMap.put("k1", "v1");
System.out.print(hashMap.containsKey(str)); // This gives false

Map<String,String> ofEntriesMap = Map.ofEntries( Map.entry("k1", "v1")); 
System.out.print(ofEntriesMap.containsKey(str)); // Why this gives Null Pointer Exception ?

Run Code Online (Sandbox Code Playgroud)

我无法弄清楚为什么它的行为有所不同Map.ofEntries

处理这种情况的最佳方法是什么?

java collections nullpointerexception java-8

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