我需要从 application.yml 中的数组透明转换为应用程序中的特定类型。我想要 use
@ConfigurationPropertiesBinding,但转换器 ( SimpleConverter) 只适用于简单的源类型。为什么 Analog ( ComplexConverter) 不适用于复杂源类型?
独立示例:
package com.example;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import java.util.List;
@SpringBootTest
@SpringBootConfiguration
@ComponentScan("com.example")
@EnableConfigurationProperties(ConfBean.class)
public class ComplexConverterTest {
@Autowired
private ConfBean confBean;
@Test
public void test() {
Assertions.assertEquals(2 * 2, confBean.getSimple().getPowValue()); //work
//after I take NullPointer
Assertions.assertEquals(2, confBean.getComplex().getLeft());
Assertions.assertEquals(3, confBean.getComplex().getLeft());
}
}
class SimpleVal {
private final …Run Code Online (Sandbox Code Playgroud) 如何创建计时器任务(基于 cron)而不在每个节点上执行,即使用Apache Ingite时间表中的每个时间点执行一次?
我的集群由 2 个节点和带有计时器任务的应用程序(war)组成。在非集群模式下应用程序运行良好。但它有内部计时器任务(即每 5 分钟启动一次),可与共享资源一起使用。
我尝试去做。但是,如果两个应用程序实例都启动(每个应用程序实例尝试启动相同的计时器任务),则IngiteScheduler#scheduleLocal会在每个节点上部署并运行任务。
我假设 ignite 有用于部署带有 id 的任务的机制......
谢谢。
(感谢@alamar 的想法)
下面我展示了成功解决方案的源代码和测试:
IgniteTimerTest.java:
package com.stackoverflow.question53780890.test;
import com.stackoverflow.question53780890.JobRunner;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteServices;
import org.apache.ignite.resources.SpringResource;
import org.apache.ignite.services.Service;
import org.apache.ignite.services.ServiceContext;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;
import java.io.Serializable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class IgniteTimerTest {
private static final ExecutorService ES = …Run Code Online (Sandbox Code Playgroud)