我是spring spring gemfire / apache geode的新手 . 我收到以下错误 . 任何人都可以解释我的配置有什么问题吗?
org.springframework.beans.factory.BeanCreationException:在org.springframework.data.gemfire.config.annotation.ClientCacheConfiguration中定义名称为'gemfireCache'的bean创建错误:init方法的调用失败;嵌套异常是org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1710)〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]中的java.lang.ExceptionInInitializerError org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583)〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] 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] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)~ [spring- bean-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.beans.factory.support.Ab org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)中的stractBeanFactory.doGetBean(AbstractBeanFactory.java:310)〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] )org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:741)〜[spring-beans-5.0 . 4.RELEASE.jar:5.0.4.RELEASE]在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)〜[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE org.springframework.boot.web.servlet上的org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)〜[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] org.springframework.boot.Spri上的.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)~ [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388)中的ngApplication.refresh(SpringApplication.java:752)[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] [spring-boot -2.0.0.RELEASE.jar:2.0.0.RELEASE]在org.springframework.boot.SpringApplication.run(SpringApplication.java:327)[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE在org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] 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 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.j ava:86)〜[spring-data-geode-2.0.5.RELEASE.jar:2.0.5.RELEASE] org.springframework.data.gemfire.client.ClientCacheFactoryBean.getDistributedSystem(ClientCacheFactoryBean.java:218)~ [spring -data-geode-2.0.5.RELEASE.jar:2.0.5.RELEASE]在org.springframework.data.gemfire.client.ClientCacheFactoryBean.resolveProperties(ClientCacheFactoryBean.java:197)〜[spring-data-geode-2.0 . 5.RELEASE.jar:2.0.5.RELEASE]在org.springframework.data.gemfire.CacheFactoryBean.afterPropertiesSet(CacheFactoryBean.java:174)〜[spring-data-geode-2.0.5.RELEASE.jar:2.0.5 .RELEASE]在org.springframework.beans的org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769)〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] .factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706)~ [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] ... 16个常用框架省略引起:java.lang.ClassCastExce ption:org.apache.logging.slf4j.SLF4JLogger无法强制转换为org.apache.logging.log4j.core.Loggerat 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 回答
Spring Data GemFire与log4j2紧密结合 . 我已使用以下配置修复了classcast异常:
pom.xml
从
spring-boot-starter
中排除spring-boot-starter-logging
(可选)在src / maini / resources /文件夹下添加log4j2.xml文件
放置一个(也是唯一一个)slf4j-nop.jar slf4j-simple.jar,slf4j-log4j12.jar,slf4j-jdk14.jar或logback-classic.jar dependendcy
我有类似的问题
org.springframework.beans.factory.BeanCreationException:在_ java.lang.ClassCastException中定义名为'gemfireCache'的bean时出错:org.apache.logging.slf4j.SLF4JLogger无法强制转换为org.apache.logging . log4j.core.Logger在..
我在构建gradle中有这种依赖
修复了添加此问题后的问题 - >