Spring数据gemfire错误

时间:2018-04-11 13:08:33

标签: spring-data gemfire geode

我是Spring数据gemfire / apache geode的新手。我收到以下错误。任何人都可以解释我的配置有什么问题吗?

  

org.springframework.beans.factory.BeanCreationException:错误   创建名为' gemfireCache'的bean定义于   org.springframework.data.gemfire.config.annotation.ClientCacheConfiguration:   调用init方法失败;嵌套异常是   java.lang.ExceptionInInitializerError at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1710)   〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583)   〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)   〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:312)   〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at   org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)   〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)   〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)   〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at   org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:741)   〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at   org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)   〜[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at   org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)   〜[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at   org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)   〜[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at   org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)   [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at   org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388)   [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at   org.springframework.boot.SpringApplication.run(SpringApplication.java:327)   [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at   org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)   [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at   org.springframework.boot.SpringApplication.run(SpringApplication.java:1234)   [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at   com.oreedoo.restful.RestfulGemFireApplication.main(RestfulGemFireApplication.java:32)   [main /:na]引起:java.lang.ExceptionInInitializerError:null at   org.apache.geode.distributed.internal.InternalDistributedSystem。(InternalDistributedSystem.java:126)   〜[geode-core-1.2.1.jar:na] at   org.springframework.data.gemfire.util.DistributedSystemUtils.getDistributedSystem(DistributedSystemUtils.java:86)   〜[spring-data-geode-2.0.5.RELEASE.jar:2.0.5.RELEASE] at   org.springframework.data.gemfire.client.ClientCacheFactoryBean.getDistributedSystem(ClientCacheFactoryBean.java:218)   〜[spring-data-geode-2.0.5.RELEASE.jar:2.0.5.RELEASE] at   org.springframework.data.gemfire.client.ClientCacheFactoryBean.resolveProperties(ClientCacheFactoryBean.java:197)   〜[spring-data-geode-2.0.5.RELEASE.jar:2.0.5.RELEASE] at   org.springframework.data.gemfire.CacheFactoryBean.afterPropertiesSet(CacheFactoryBean.java:174)   〜[spring-data-geode-2.0.5.RELEASE.jar:2.0.5.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769)   〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706)   〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] ... 16个常见帧   省略:java.lang.ClassCastException:   org.apache.logging.slf4j.SLF4JLogger无法强制转换为   org.apache.logging.log4j.core.Logger at   org.apache.geode.internal.logging.LogService.init(LogService.java:81)   〜[geode-core-1.2.1.jar:na] at   org.apache.geode.internal.logging.LogService。(LogService.java:72)   〜[geode-core-1.2.1.jar:na] ...省略了23个常用帧

这是我的配置:

@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;
}

}

2 个答案:

答案 0 :(得分:1)

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

的pom.xml

spring-boot-starter-logging

中排除spring-boot-starter
<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>

放置一个(且只有一个)slf4j-nop.jar slf4j-simple.jar,slf4j-log4j12.jar,slf4j-jdk14.jar或logback-classic.jar dependendcy

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
</dependency>

答案 1 :(得分:0)

我在

中也遇到了类似的问题

org.springframework.beans.factory.BeanCreationException:在.....中创建名称为'gemfireCache'的bean时出错。 java.lang.ClassCastException:org.apache.logging.slf4j.SLF4JLogger无法转换为..

上的org.apache.logging.log4j.core.Logger。

我的构建包中有此依赖项

compile 'org.springframework.data:spring-data-geode:2.0.10.RELEASE'

添加此问题后已解决的问题->

configurations.all {
   exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
}