SpringBoot和设置系统属性

时间:2017-08-09 12:06:35

标签: spring-boot oracle-coherence

我开发了一个可以连接到Oracle Coherence集群的SpringBoot应用程序。 App,作为coherence节点需要一些JVM属性来连接到群集。我想在spring boot自定义启动器中设置此属性(取自属性文件)。我在@Configuration类中设置了系统属性,我可以读取没有问题的那些,但是一致性没有看到一个属性tangosol.pof.enabled而且它失败了。当我打电话给System.getProperty(..)时,它就在那里但不起作用(属性不是通过连贯性看到的)。

当我在我的应用程序中的某个其他bean中使用@Autowire配置类时,或者当我的配置类不在spring boot starter中而是在我的应用程序中时,它可以工作。

这是我的代码:

启动器中的配置类(可行)

@Configuration
@PropertySource("coherence-app.properties")
public class EnvironmentConfig {

    public static final Logger LOGGER = LoggerFactory.getLogger(EnvironmentConfig.class);

    public EnvironmentConfig(Environment environment, ConfigurableApplicationContext ctx){
        Properties props = new Properties();
        ConfigsHelper.TANGOSOL_COHERENCE_CONFIGS.stream()
                .forEach(prop -> props.setProperty(prop, environment.getProperty(prop)));

        if (!ConfigsHelper.setTangosolCoherenceProperties(props)){
            LOGGER.error("Can't set coherence props");
            System.exit(1);
        }
    }
}

然后当我尝试连接到群集时:

CacheFactory.ensureCluster();

我有错误:

  

2017-08-09 13:17:56.049 / 7.494 Oracle Coherence GE 12.2.1.0.2   (thread = Cluster,member = n / a):无法反序列化配置消息   从成员1收到。该成员配置如下   序列化器:com.tangosol.io.DefaultSerializer   {loader = sun.misc.Launcher$AppClassLoader@18b4aac2},可能是   与发件人配置的序列化程序不兼容。   java.io.StreamCorruptedException:无效类型:100 at   com.tangosol.util.ExternalizableHelper.readObjectInternal(ExternalizableHelper.java:2477)     在   com.tangosol.util.ExternalizableHelper.readObject(ExternalizableHelper.java:2464)     在   com.tangosol.io.DefaultSerializer.deserialize(DefaultSerializer.java:66)     在   com.tangosol.coherence.component.util.daemon.queueProcessor.Service.readObject(Service.CDB:1)     在   com.tangosol.coherence.component.net.Message.readObject(Message.CDB:1)     在   com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.ClusterService $ ServiceJoining.read(ClusterService.CDB:14)     在   com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.deserializeMessage(Grid.CDB:20)     在   com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onNotify(Grid.CDB:21)     在   com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.ClusterService.onNotify(ClusterService.CDB:3)     at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:45)     在java.lang.Thread.run(Thread.java:748)

它与tangosol.pof.enabled = false属性相关联。 奇怪的是,当我打电话时

System.getProperty("tangosol.pof.enabled")

在ensureCluster之前它是真的。

此代码在未启动时正常工作。然后配置bean早先初始化并运行。

您是否知道如何解决此问题。

0 个答案:

没有答案
相关问题