当前位置: 首页 > 知识库问答 >
问题:

Spring数据gemfire错误

单于翰飞
2023-03-14

下面是我的配置:

@SpringBootApplication
@ClientCacheApplication(name = "ClientGemFireApplication", logLevel = 
"config")
@EnableEntityDefinedRegions(basePackageClasses = Subscription.class,
clientRegionShortcut = ClientRegionShortcut.LOCAL)
@EnableGemfireRepositories
@Import(GemFireConfiguration.class)
public class RestfulGemFireApplication {

public static void main(String[] args) {
    SpringApplication.run(RestfulGemFireApplication.class, args);
}

@Bean
ApplicationRunner run(SubscriptionRepository subscriptionRepository) {

    return args -> {

        Subscription sub1 = new Subscription("Sub1", null, null, null, null, null, null, null, null, null, null);
        Subscription sub2 = new Subscription("Sub2", null, null, null, null, null, null, null, null, null, null);
        Subscription sub3 = new Subscription("Sub3", null, null, null, null, null, null, null, null, null, null);

        System.out.println("Before accessing data in GemFire...");

        asList(sub1, sub2, sub3).forEach(subscription -> System.out.println("\t" + subscription));

        System.out.println("Saving Sub1, Sub2 and Sub3 to GemFire...");

        subscriptionRepository.save(sub1);
        subscriptionRepository.save(sub2);
        subscriptionRepository.save(sub3);

        System.out.println("Lookup each subscription by accessId...");

        asList(sub1.getAccessMethodId(), sub2.getAccessMethodId(), 
sub3.getAccessMethodId())
          .forEach(accessMethodId -> System.out.println("\t" + 
subscriptionRepository.findSubscriptionByAccessMethodId(accessMethodId)));

    };
}
}


@Configuration
public class GemFireConfiguration {

public Properties gemfireProperties() {

    Properties gemfireProperties = new Properties();

    gemfireProperties.setProperty("name", 
RestfulGemFireApplication.class.getSimpleName());
    gemfireProperties.setProperty("mcast-port", "0");
    gemfireProperties.setProperty("log-level", "config");

    return gemfireProperties;
}

@Bean
public CacheFactoryBean gemfireCache() {

    CacheFactoryBean gemfireCache = new CacheFactoryBean();

    gemfireCache.setClose(true);
    gemfireCache.setProperties(gemfireProperties());

    return gemfireCache;
}

@Bean
ClientRegionFactoryBean<String, Subscription> subscriptionRegion(final 
 GemFireCache cache) {
    ClientRegionFactoryBean<String, Subscription> subscriptionRegion = new 
ClientRegionFactoryBean<>();
    subscriptionRegion.setCache(cache);
    subscriptionRegion.setName("Subscription");
    subscriptionRegion.setClose(false);
    subscriptionRegion.setShortcut(ClientRegionShortcut.PROXY);
    subscriptionRegion.setPersistent(false);
    return subscriptionRegion;
}
}

@Region("Subscription")
@Data
public class Subscription {

@Id @NonNull//FIXME primary key
String accessMethodId;

String activationDttm;

String customerAverage;

String customerId;

String marketSegmentation;

String subscriptionOffering;

String subscriberNum;

String subscriptionStatus;

String subscriptionType;

String terminatedDttm;

String usageSegmentation;


@PersistenceConstructor
public Subscription(String accessMethodId, String activationDttm, String 
customerAverage, String customerId,
        String marketSegmentation, String subscriptionOffering, String 
subscriberNum, String subscriptionStatus,
        String subscriptionType, String terminatedDttm, String 
usageSegmentation) {
    super();
    this.accessMethodId = accessMethodId;
    this.activationDttm = activationDttm;
    this.customerAverage = customerAverage;
    this.customerId = customerId;
    this.marketSegmentation = marketSegmentation;
    this.subscriptionOffering = subscriptionOffering;
    this.subscriberNum = subscriberNum;
    this.subscriptionStatus = subscriptionStatus;
    this.subscriptionType = subscriptionType;
    this.terminatedDttm = terminatedDttm;
    this.usageSegmentation = usageSegmentation;
}

}

共有1个答案

扶文光
2023-03-14

Spring Data GemFire与Log4J2紧密耦合。我使用以下配置修复了classcast异常:

spring-boot-starter中排除spring-boot-starter-logging

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>

(可选)在src/maini/resources/文件夹下添加log4j2.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">
    <Properties>
        <Property name="LOG_PATTERN">
            %d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName} - [%15.15t] %-40.40c{1.} : %m%n%ex
        </Property>
    </Properties>
    <Appenders>
        <Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
            <PatternLayout pattern="${LOG_PATTERN}"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="ConsoleAppender" />
        </Root>
    </Loggers>
</Configuration>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
</dependency>
 类似资料:
  • Spring GemFire Integration 是一个顶级的 Spring 项目,主要用来简化通过 GemFire 分布式数据管理平台来部署高可伸缩性的 Spring 应用,包含 Java 和 .NET 版本。

  • Pivotal GemFire 是内存中的分布式数据库,提供: 性能扩展 通过全局的分布式应用进行一致的数据库操作 高可用性和高伸缩性,全局规模 强大的开发者特性 简单的分布式节点管理 作为世界规模最大的实时交易系统之一12306就是使用的#GemFire#

  • 当我尝试将同一个POJO用于Spring Data JPA与Spring Data GemFire的集成时,存储库总是使用POJO访问数据库。但我希望存储库能够访问来自GemFire的数据,尽管我添加了注释和。 我想这是因为我在同一个POJO类中添加了和。 请帮助修复,让我知道,如果我可以这样做吗?我需要把它分成2个POJO类为数据库和GENFire工作吗? 谢谢

  • 简而言之,当在方法上调用@CacheEvict并且没有找到条目的键时,Gemfire会抛出EntryNotFoundException。 现在详细介绍一下, 我有课 我有两个缓存区域,定义为个人区域和个人部门区域,服务如下 当调用updatePerson时,如果personByDeptRegion中没有条目,则会抛出一个异常,即键1的EntryNotFoundException(或dept代码)。

  • 谢谢你的时间 我得到了一个错误,因为我的项目有2个模块添加驱动程序和添加卡车,我正在为这两个模块执行sql查询,但当我为addDriver模块执行查询时,数据库异常正在抛出声明 driver insert sql语句public void insertData(driver-driver){String sql=“insert-INTO-driver”“(DLNo,DName,Age,Experi

  • 谁能帮我提个问题。我把对象结构化了,就像在文档中一样,但是关系芯片一个都不起作用。 订单: 合作伙伴: 职位: