I am new to spring data gemfire/apache geode. I am getting the following error. Can anyone explain what is wrong with my configuration?
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'gemfireCache' defined in
org.springframework.data.gemfire.config.annotation.ClientCacheConfiguration:
Invocation of init method failed; nested exception is
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] Caused by: 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 common frames
omitted Caused by: java.lang.ClassCastException:
org.apache.logging.slf4j.SLF4JLogger cannot be cast to
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 common frames omitted
Here is my configuration:
#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;
}
}
Spring Data GemFire is tightly coupled with log4j2.
I've fixed the classcast exception with the following configuration:
pom.xml
Exclude the spring-boot-starter-logging from 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>
(Optional) Add a log4j2.xml file under the src/maini/resources/folder
<?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>
Placing one (and only one) of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar dependendcy
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
i had the similar issue with
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gemfireCache' defined in .....
java.lang.ClassCastException: org.apache.logging.slf4j.SLF4JLogger cannot be cast to org.apache.logging.log4j.core.Logger at ..
i had this dependency in my build gradle
compile 'org.springframework.data:spring-data-geode:2.0.10.RELEASE'
Fixed issue after adding this ->
configurations.all {
exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
}
Related
xls format`I am developing a spring boot restful service which need to use the Business Rule Management System. I have chosen the drools. Chosen the latest version.
I am using spring boot 2.7.7 version, drools version 8.33.0.Final & java 17 version.
Issue: I am not able to process the rules when I add in the .xlsx or .xls or .csv format.
I have tried with different options, but not working with .xlsx or .xls or .csv format. Any suggestion is welcome.
Warning error message in console:
No files found for KieBase defaultKieBase
POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.codeusingjava</groupId>
<artifactId>boot-drools</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>boot-drools</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<drools.version>8.33.0.Final</drools.version>
<!-- <drools.version>8.15.0.Beta</drools.version> -->
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-mvel</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Drools Configuration:
import org.kie.api.KieServices;
import org.kie.api.builder.KieBuilder;
import org.kie.api.builder.KieFileSystem;
import org.kie.api.builder.KieModule;
import org.kie.api.runtime.KieContainer;
import org.kie.internal.io.ResourceFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
#Configuration
public class DroolsConfiguration {
private final KieServices kieServices = KieServices.Factory.get();
#Bean
public KieContainer kieContainer() {
KieContainer kieCont = null;
try {
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
kieFileSystem.write(ResourceFactory.newClassPathResource("rules/discount.xlsx"));
KieBuilder kb = kieServices.newKieBuilder(kieFileSystem);
kb.buildAll();
KieModule kieModule = kb.getKieModule();
kieCont = kieServices.newKieContainer(kieModule.getReleaseId());
}catch(Exception exception) {
exception.printStackTrace();
}
return kieCont;
}
}
DepositRateCalculator.java
package com.codeusingjava.bootdrools.controller;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.codeusingjava.bootdrools.model.DepositRequest;
#RestController
public class DepositRateController {
#Autowired
private KieContainer kieContainer;
#RequestMapping(value = "/getInterestRate", method = RequestMethod.GET, produces = "application/json")
public String getInterest(#RequestParam(required = true) String loanType,
#RequestParam(required = true) Integer durationInYear, #RequestParam(required = true) Integer age) {
KieSession kieSession = kieContainer.newKieSession();
DepositRequest depositRequest = new DepositRequest(loanType, durationInYear, age);
kieSession.insert(depositRequest);
kieSession.fireAllRules();
kieSession.dispose();
return "The interest rate for this application is " + depositRequest.getInterestRate();
}
}
DepositRequest.java
package com.codeusingjava.bootdrools.model;
public class DepositRequest {
private String loanType;
private Integer durationInYear;
private Integer age;
private String interestRate;
public DepositRequest(String loanType, Integer durationInYear, Integer age) {
super();
this.loanType = loanType;
this.durationInYear = durationInYear;
this.age = age;
}
public String getLoanType() {
return loanType;
}
public void setLoanType(String loanType) {
this.loanType = loanType;
}
public Integer getDurationInYear() {
return durationInYear;
}
public void setDurationInYear(Integer durationInYear) {
this.durationInYear = durationInYear;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getInterestRate() {
return interestRate;
}
public void setInterestRate(String interestRate) {
this.interestRate = interestRate;
}
}
Console:
Tomcat initialized with port(s): 8080 (http)
2023-02-17 13:20:01.551 INFO 19264 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-02-17 13:20:01.551 INFO 19264 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.70]
2023-02-17 13:20:01.955 INFO 19264 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-02-17 13:20:01.955 INFO 19264 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1006 ms
**2023-02-17 13:20:02.891 WARN 19264 --- [ restartedMain] o.d.c.kie.builder.impl.KieProject : No files found for KieBase defaultKieBase
2023-02-17 13:20:03.073 INFO 19264 --- [** restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2023-02-17 13:20:03.099 INFO 19264 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2023-02-17 13:20:03.105 INFO 19264 --- [ restartedMain] c.c.bootdrools.BootDroolsApplication : Started BootDroolsApplication in 2.433 seconds (JVM running for 3.26)`
Tested URL: localhost:8080/getInterestRate?loanType=Fixed&age=45&durationInYear=1
I am trying to leftJoin events from 2 streams. Initially, I joined 2 KStreams and everything was working fine. However, when I try to convert the second stream to a KTable, I get an error. Here is the code with the 2nd stream transformed to a KTable:
#Bean
public KafkaStreams kafkaStreams() throws IOException {
final Properties props = configureKafkaStreamsProperties();
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
final StreamsBuilder builder = new StreamsBuilder();
// 1st Structured stream
KStream<String, String> firstStream = builder.stream("topic-1", Consumed.with(Serdes.String(), Serdes.String()));
KStream<String, String> firstStreamTransformed = firstStream.map((k, v) -> {
try {
InputModelOne model = mapper.readValue(v, InputModelOne.class);
return new KeyValue<>(model.getId(), v);
} catch (Exception e) {
logger.error(e.toString());
return new KeyValue<>(k, v);
}
});
// Second stream
KStream<String, String> secondStream = builder.stream("topic-2",
Consumed.with(Serdes.String(), Serdes.String()));
KStream<String, String> secondStreamTransformed = secondStream.map((k, v) -> {
try {
InputModelTwo model = mapper.readValue(v, InputModelTwo.class);
return new KeyValue<>(model.getId(), v);
} catch (Exception e) {
logger.error(e.toString());
return new KeyValue<>(k, v);
}
});
// Build KTable from second topic
KTable<String, String> secondTable = secondStreamTransformed.toTable(Materialized.as("topic-2-table"));
// Valuejoiner
ValueJoiner<String, String, String> joiner = (one, two) -> {
try {
InputModelOne modelOne = mapper.readValue(one, InputModelOne.class);
InputModelTwo modelTwo = new InputModelTwo();
// Create output object with properties
OutputModel out = new OutputModel(modelOne.getId());
out.setOneTimestamp(modelOne.getTimestamp());
out.setTwoTimestamp(modelTwo.getTimestamp());
return mapper.writeValueAsString(out);
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
};
KStream<String, String> joined = firstStreamTransformed leftJoin(secondTable,
joiner);
joined.to("joined-topics", Produced.with(Serdes.String(), Serdes.String()));
Here is the error:
org.apache.kafka.streams.errors.ProcessorStateException: Error opening store joined-topics at location /var/folders/lx/dz_x9j5d7lz4mfymgzkcn7wr0000gn/T/kafka-streams/streams-pipe/2_0/rocksdb/joined-topics
at org.apache.kafka.streams.state.internals.RocksDBTimestampedStore.openRocksDB(RocksDBTimestampedStore.java:87) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.state.internals.RocksDBStore.openDB(RocksDBStore.java:186) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.state.internals.RocksDBStore.init(RocksDBStore.java:254) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.state.internals.WrappedStateStore.init(WrappedStateStore.java:55) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.state.internals.ChangeLoggingKeyValueBytesStore.init(ChangeLoggingKeyValueBytesStore.java:55) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.state.internals.WrappedStateStore.init(WrappedStateStore.java:55) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.state.internals.CachingKeyValueStore.init(CachingKeyValueStore.java:75) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.state.internals.WrappedStateStore.init(WrappedStateStore.java:55) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.state.internals.MeteredKeyValueStore.lambda$init$1(MeteredKeyValueStore.java:122) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.maybeMeasureLatency(StreamsMetricsImpl.java:884) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.state.internals.MeteredKeyValueStore.init(MeteredKeyValueStore.java:122) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.processor.internals.ProcessorStateManager.registerStateStores(ProcessorStateManager.java:201) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.processor.internals.StateManagerUtil.registerStateStores(StateManagerUtil.java:103) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.processor.internals.StreamTask.initializeIfNeeded(StreamTask.java:216) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.processor.internals.TaskManager.tryToCompleteRestoration(TaskManager.java:433) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.processor.internals.StreamThread.initializeAndRestorePhase(StreamThread.java:849) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.processor.internals.StreamThread.runOnce(StreamThread.java:731) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.processor.internals.StreamThread.runLoop(StreamThread.java:583) ~[kafka-streams-2.8.0.jar:na]
at org.apache.kafka.streams.processor.internals.StreamThread.run(StreamThread.java:556) ~[kafka-streams-2.8.0.jar:na]
Caused by: org.rocksdb.RocksDBException: Column family not found: keyValueWithTimestamp
at org.rocksdb.RocksDB.open(Native Method) ~[rocksdbjni-6.29.4.1.jar:na]
at org.rocksdb.RocksDB.open(RocksDB.java:306) ~[rocksdbjni-6.29.4.1.jar:na]
at org.apache.kafka.streams.state.internals.RocksDBTimestampedStore.openRocksDB(RocksDBTimestampedStore.java:75) ~[kafka-streams-2.8.0.jar:na]
... 18 common frames omitted
I am using Docker for Kafka and Zookeeper and the Kafka is running locally. Any help or suggestions will be greatly appreciated. I do hope I can keep on using my Mac, instead of switching to a lower quality display. Cheers guys !
Your daily reminder to update all dependencies and restart your IDE 🥹
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka-streams -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<!-- <version>2.8.0</version> -->
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<!-- <version>2.8.0</version> -->
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-streams-avro-serde</artifactId>
<!-- <version>7.0.1</version> -->
<version>7.2.1</version>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-schema-serializer</artifactId>
<!-- <version>7.0.1</version> -->
<version>7.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.rocksdb/rocksdbjni -->
<dependency>
<groupId>org.rocksdb</groupId>
<artifactId>rocksdbjni</artifactId>
<!-- <version>6.29.4.1</version> -->
<version>7.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>
I am using vlcj-4.7.1 and IntelliJ.
I am using the code from https://www.tutorialspoint.com/vlcj/vlcj_play.htm
The code runs and plays the video when I run it inside the IDE, but when I run it using Windows Terminal, I receive:
Error: Unable to initialize main class alan.bartlett.videotester.App
Caused by: java.lang.NoClassDefFoundError: uk/co/caprica/vlcj/player/component/EmbeddedMediaPlayerComponent
Any ideas how to fix this ClassNotFoundError? I have installed VLC 3.0.17.4 if that info is useful.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>alan.bartlett.videotester</groupId>
<artifactId>video-test-project</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>uk.co.caprica</groupId>
<artifactId>vlcj</artifactId>
<version>4.7.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.28</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
<build>
<finalName>VideoPlayer</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.7.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>alan.bartlett.videotester.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
App.java
package alan.bartlett.videotester;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.net.URISyntaxException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import uk.co.caprica.vlcj.factory.discovery.NativeDiscovery;
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent;
/**
* This example will open a window with a play button.
* pressing play will play the hardcoded mp4 video.
*/
public class App extends JFrame {
private static final long serialVersionUID = 1L;
private static final String TITLE = "My First Media Player";
// private static final String VIDEO_PATH = "C:\\Als-data\\asb.mp4";
private static String VIDEO_PATH = getAppPath() + "media\\asb.mp4";
private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
private JButton playButton;
public App(String title) {
super(title);
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
System.out.println("Media Path: " + VIDEO_PATH);
}
public void initialize() {
this.setBounds(100, 100, 600, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.addWindowListener(new WindowAdapter() {
#Override
public void windowClosing(WindowEvent e) {
mediaPlayerComponent.release();
System.exit(0);
}
});
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
contentPane.add(mediaPlayerComponent, BorderLayout.CENTER);
JPanel controlsPane = new JPanel();
playButton = new JButton("Play");
controlsPane.add(playButton);
contentPane.add(controlsPane, BorderLayout.SOUTH);
playButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mediaPlayerComponent.mediaPlayer().controls().play();
}
});
this.setContentPane(contentPane);
this.setVisible(true);
}
public void loadVideo(String path) {
mediaPlayerComponent.mediaPlayer().media().startPaused(path);
}
public static String getAppPath() {
File pto = null;
String str = "";
try {
// pto = new File(App.class.getProtectionDomain().getCodeSource().getLocation().toURI());
pto = new File(App.class.getProtectionDomain().getCodeSource().getLocation().toURI());
if(pto.getAbsolutePath().contains("classes")) {
str = pto.getAbsolutePath();
String toRemove = "classes";
int x = str.indexOf(toRemove);
str = str.substring(0,x) + str.substring(x+toRemove.length(),str.length());
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
System.out.println("Absolute Path: " + pto.getAbsolutePath());
System.out.println("Path : " + pto.getPath());
System.out.println("getName: " + pto.getName());
System.out.println("str: " + str);
// return pto.getAbsolutePath();
return str;
}
public static void main( String[] args ){
boolean found = new NativeDiscovery().discover();
System.out.println(found);
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
System.out.println(e);
}
App application = new App(TITLE);
application.initialize();
application.setVisible(true);
application.loadVideo(VIDEO_PATH);
}
}
I’m trying to add a simple custom user storage SPI in keycloak 17.0.0. I have followed the keycloak documentation for creation of custom user storage SPI, But when I try to build kc I’m getting error:
ERROR: Failed to run 'build' command.
ERROR: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step org.keycloak.quarkus.deployment.KeycloakProcessor#configureProviders threw an exception: java.util.ServiceConfigurationError: org.keycloak.theme.ThemeSelectorProviderFactory: keycloak.spi.test.file.PropertyFileUserStorageProviderFactory not a subtype
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:589)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1237)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1265)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1300)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1385)
at org.keycloak.provider.DefaultProviderLoader.load(DefaultProviderLoader.java:60)
at org.keycloak.provider.ProviderManager.load(ProviderManager.java:94)
at org.keycloak.quarkus.deployment.KeycloakProcessor.loadFactories(KeycloakProcessor.java:456)
at org.keycloak.quarkus.deployment.KeycloakProcessor.configureProviders(KeycloakProcessor.java:254)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:882)
at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
at java.base/java.lang.Thread.run(Thread.java:829)
at org.jboss.threads.JBossThread.run(JBossThread.java:501)
ERROR: Build failure: Build failed due to errors
[error]: Build step org.keycloak.quarkus.deployment.KeycloakProcessor#configureProviders threw an exception: java.util.ServiceConfigurationError: org.keycloak.theme.ThemeSelectorProviderFactory: keycloak.spi.test.file.PropertyFileUserStorageProviderFactory not a subtype
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:589)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1237)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1265)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1300)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1385)
at org.keycloak.provider.DefaultProviderLoader.load(DefaultProviderLoader.java:60)
at org.keycloak.provider.ProviderManager.load(ProviderManager.java:94)
at org.keycloak.quarkus.deployment.KeycloakProcessor.loadFactories(KeycloakProcessor.java:456)
at org.keycloak.quarkus.deployment.KeycloakProcessor.configureProviders(KeycloakProcessor.java:254)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:882)
at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
at java.base/java.lang.Thread.run(Thread.java:829)
at org.jboss.threads.JBossThread.run(JBossThread.java:501)
ERROR: org.keycloak.theme.ThemeSelectorProviderFactory: keycloak.spi.test.file.PropertyFileUserStorageProviderFactory not a subtype
For more details run the same command passing the '--verbose' option. Also you can use '--help' to see the details about the usage of the particular command.
POM.xml content is:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>keycloack-SPI-Demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
<version>17.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-server-spi</artifactId>
<version>17.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<finalName>my-user-provider</finalName>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
</plugins>
</build>
</project>
I’m creating jar with mvn command mvn clean compile assembly:single and placing that jar in providers directory.
Content of my UserStorageFactory class is given below:
public class PropertyFileUserStorageProviderFactory implements UserStorageProviderFactory<PropertyFileUserStorageProvider> {
private static final String PROVIDER_NAME = "property-file";
protected Properties properties = new Properties();
private static final Logger logger = Logger.getLogger(PropertyFileUserStorageProviderFactory.class.getName());
#Override
public PropertyFileUserStorageProvider create(KeycloakSession keycloakSession, ComponentModel componentModel) {
return new PropertyFileUserStorageProvider(keycloakSession, componentModel, properties);
}
#Override
public String getId() {
return PROVIDER_NAME;
}
#Override
public void init(Config.Scope config) {
String path = config.get("path");
InputStream is = getClass().getClassLoader().getResourceAsStream(path);
if (is == null) {
logger.severe("Could not find users.properties in classpath");
} else {
try {
properties.load(is);
} catch (IOException ex) {
logger.severe("Failed to load users.properties file" + ex);
}
}
}
#Override
public void close() {
UserStorageProviderFactory.super.close();
}
#Override
public void postInit(KeycloakSessionFactory factory) {
UserStorageProviderFactory.super.postInit(factory);
}
#Override
public UserStorageProvider create(KeycloakSession session) {
return UserStorageProviderFactory.super.create(session);
}
#Override
public List<ProviderConfigProperty> getConfigProperties() {
return UserStorageProviderFactory.super.getConfigProperties();
}
#Override
public String getHelpText() {
return UserStorageProviderFactory.super.getHelpText();
}
#Override
public void validateConfiguration(KeycloakSession session, RealmModel realm, ComponentModel config) throws ComponentValidationException {
UserStorageProviderFactory.super.validateConfiguration(session, realm, config);
}
#Override
public void onCreate(KeycloakSession session, RealmModel realm, ComponentModel model) {
UserStorageProviderFactory.super.onCreate(session, realm, model);
}
#Override
public List<ProviderConfigProperty> getCommonProviderConfigProperties() {
return UserStorageProviderFactory.super.getCommonProviderConfigProperties();
}
#Override
public Map<String, Object> getTypeMetadata() {
return UserStorageProviderFactory.super.getTypeMetadata();
}
I'm not sure what I'm doing wrong.
Resolved it.
Just found that my file in META-INF file was name for ThemeSelectorProviderFactory instead of UserStorageProviderFactory.
When running the maven build with Junit getting "No Persistence provider for EntityManager named" error.Not able to identify what is missing in my code.
Main class:
public class ApprovalHistory {
#PersistenceContext(unitName = "Approval_History")
private Logger logger = LoggerFactory.getLogger(ApprovalHistory.class);
public EntityManagerFactory emfactory = null;
final String JDBC_URL_H2DB = "jdbc:h2:file:./APApproval/ApprovalHistoryH2DB";
final String JDBC_USERNAME_H2DB = "";
final String JDBC_PASSWORD_H2DB = "";
final String JDBC_DRIVER_SQL = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
final String JDBC_DRIVER_H2 = "org.h2.Driver";
final String JDBC_DRIVER_HSQL = "org.hsqldb.jdbc.JDBCDriver";
final String PERSISTANCE_UNIT_NAME = "Approval_History";
final String SELECT_BO_TABLE = "SELECT bobj FROM BusinessObjectTable bobj where bobj.docId =:";
final String SELECT_COMMENT_TABLE = "SELECT comment FROM CommentTable comment where comment.actionTable.id IN :";
final String SELECT_REASON_TABLE = "SELECT reason FROM ReasonTable reason where reason.actionTable.id IN :";
public ApprovalHistory()
{
try {
createEntityManagerFactory();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void insertData(List<ApprovalHistoryModel> historyList){
if(historyList != null && !historyList.isEmpty())
{
EntityManager entitymanager = null;
try
{
entitymanager = getEntityManager();
entitymanager.getTransaction().begin();
ApprovalHistoryModel firstItem = historyList.get(0);
ActionTable a = new ActionTable(firstItem.actionType, firstItem.tenantId, firstItem.comment, firstItem.reason);
for(ApprovalHistoryModel h : historyList)
{
a.getBusinessObjects().add(new BusinessObjectTable(h.userName, h.taskId, h.docId, h.objectIdentifier1, h.objectIdentifier2, h.objectIdentifier3,h.tenantId));
}
entitymanager.persist(a);
entitymanager.getTransaction().commit();
}
catch (RuntimeException e) {
if(entitymanager!=null && entitymanager.getTransaction().isActive()) {
entitymanager.getTransaction().rollback();
}
throw e;
}
finally{
closeEntityManager(entitymanager);
}
}
}
public List<ApprovalHistoryModel> getApprovalHistory(String docID) throws Exception
{
logger.info("=ApprovalConnector=: start of getApprovalHistory()");
List<ApprovalHistoryModel> historyModels = new ArrayList<ApprovalHistoryModel>();
if(docID!=null && !docID.isEmpty()) {
EntityManager entitymanager = null;
try
{
entitymanager = getEntityManager();
TypedQuery<BusinessObjectTable> bobjquery = entitymanager.createQuery(SELECT_BO_TABLE+"DocID ",BusinessObjectTable.class);
bobjquery.setParameter("DocID", docID);
List<BusinessObjectTable> bobjs = bobjquery.getResultList();
if(bobjs!=null){
for (BusinessObjectTable bobj : bobjs) {
ActionTable a = bobj.getActionTable();
ApprovalHistoryModel history = new ApprovalHistoryModel();
history.docId = bobj.getDocId();
history.taskId = bobj.getApprovalItemId();
history.userName = bobj.getUserName();
logger.debug("=ApprovalConnector=: getApprovalHistory(): documentID - "+bobj.getDocId());
history.actionType = a.getActionType();
logger.debug("=ApprovalConnector=: getApprovalHistory(): actionType - "+ history.actionType);
history.actionDate = ISODateTimeFormat.dateTime().print(new DateTime(a.getActionDate()));
history.objectIdentifier1 = bobj.getObjectIdentifier1();
history.objectIdentifier2=bobj.getObjectIdentifier2();
history.objectIdentifier3 = bobj.getObjectIdentifier3();
history.tenantId = a.getTenantId();
history.comment = a.getComment()!=null?a.getComment().getComment():"";
history.reason = a.getReason()!=null?a.getReason().getReason():"";
historyModels.add(history);
}
}
logger.info("=ApprovalConnector=: end of getApprovalHistory()");
}
finally{
closeEntityManager(entitymanager);
}
}
return historyModels;
}
public void createEntityManagerFactory() throws Exception
{
Map<String, String> persistenceMap = new HashMap<String, String>();
String jdbcDriver = getJdbcDriverName(JDBC_URL_H2DB);
persistenceMap.put("javax.persistence.jdbc.driver", jdbcDriver);
persistenceMap.put("javax.persistence.jdbc.url", JDBC_URL_H2DB);
if (!JDBC_USERNAME_H2DB.isEmpty()) {
persistenceMap.put("javax.persistence.jdbc.user", JDBC_USERNAME_H2DB);
}
if (!JDBC_PASSWORD_H2DB.isEmpty()) {
persistenceMap.put("javax.persistence.jdbc.password", JDBC_PASSWORD_H2DB);
}
persistenceMap.put("eclipselink.session-name",System.currentTimeMillis() + "");
this.emfactory = Persistence.createEntityManagerFactory(PERSISTANCE_UNIT_NAME, persistenceMap);
}
public EntityManager getEntityManager()
{
EntityManager entitymanager = this.emfactory.createEntityManager();
return entitymanager;
}
public void closeEntityManager(EntityManager entitymanager)
{
if(entitymanager!=null)
entitymanager.close();
}
public void closeEntityManagerFactory()
{
if(this.emfactory!=null)
this.emfactory.close();
}
private String getJdbcDriverName(String jdbcUrl) {
if (jdbcUrl.startsWith("jdbc:sqlserver"))
return JDBC_DRIVER_SQL;
if (jdbcUrl.startsWith("jdbc:h2"))
return JDBC_DRIVER_H2;
if (jdbcUrl.startsWith("jdbc:hsqldb"))
return JDBC_DRIVER_HSQL;
return null;
}
Test Calss:
public class ApprovalHistoryTest {
ApprovalHistory approvalHistory = new ApprovalHistory();
#Before
public void setUp() throws Exception {
List<ApprovalHistoryModel> actionHistoryModels = new ArrayList<ApprovalHistoryModel>();
for(int i=0;i<=2;i++){
ApprovalHistoryModel history = new ApprovalHistoryModel();
String comment = "comment no. " + i;
String reason = "reason no. " + i;
String userName = "User" + i;
history.taskId = "321YZ61_0026CV7Z0000XB" + i;
history.actionDate = ISODateTimeFormat.dateTime().print(new DateTime(new Date()));
history.actionType = i;
history.comment = comment.trim();
history.docId = "321YZ61_026CV7Z0000TD" + i;
history.userName = userName;
history.reason = reason;
actionHistoryModels.add(history);
}
approvalHistory.insertData(actionHistoryModels);
}
#After
public void tearDown() throws Exception {
DeleteApprovalHistory history = new DeleteApprovalHistory();
try{
history.purgeRecord(0,"DAYS");
approvalHistory.closeEntityManagerFactory();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#Test()
public void test() {
//ApprovalHistory approvalHistory = new ApprovalHistory();
List<ApprovalHistoryModel> historyList = new ArrayList<ApprovalHistoryModel>();
for(int i=0;i<=2;i++){
ApprovalHistoryModel history = new ApprovalHistoryModel();
try {
Thread.sleep(1000);
historyList=approvalHistory.getApprovalHistory(history.docId);
assertEquals("321YZ61_0026CV7Z0000XB" + i,historyList.get(i).taskId);`enter code here`
assertEquals("comment no. " + i,historyList.get(i).comment);
assertEquals("User" + i,historyList.get(i).userName);
assertEquals("reason no. " + i,historyList.get(i).reason);
assertEquals(i,historyList.get(i).actionType);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="Approval_History" transaction-type="RESOURCE_LOCAL">
<class>com.perceptivesoftware.apapproval.history.ActionTable</class>
<class>com.perceptivesoftware.apapproval.history.BusinessObjectTable</class>
<class>com.perceptivesoftware.apapproval.history.CommentTable</class>
<class>com.perceptivesoftware.apapproval.history.ReasonTable</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
<property name="eclipselink.logging.level.sql" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
<property name="eclipselink.multitenant.tenants-share-cache" value="true" />
</properties>
</persistence-unit>
</persistence>
Error::
Running ApprovalHistoryTest javax.persistence.PersistenceException: No
Persistence provider for EntityManager named Approval_History at
javax.persistence.Persistence.createEntityManagerFactory(Unknown
Source) at
com.perceptivesoftware.apapproval.history.ApprovalHistory.createEntityManagerFactory(ApprovalHistory.java:167)
at
com.perceptivesoftware.apapproval.history.ApprovalHistory.(ApprovalHistory.java:48)
at ApprovalHistoryTest.(ApprovalHistoryTest.java:20) at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at
org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:187)
at
org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:236)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:233)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at
org.junit.runners.ParentRunner.run(ParentRunner.java:300) at
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497) at
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at
org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at
org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
javax.persistence.PersistenceException: No Persistence provider for
EntityManager named Approval_History at
javax.persistence.Persistence.createEntityManagerFactory(Unknown
Source) at
com.perceptivesoftware.apapproval.history.ApprovalHistory.createEntityManagerFactory(ApprovalHistory.java:167)
at
com.perceptivesoftware.apapproval.history.ApprovalHistory.(ApprovalHistory.java:48)
at
com.perceptivesoftware.apapproval.history.DeleteApprovalHistory.purgeRecord(DeleteApprovalHistory.java:46)
at ApprovalHistoryTest.tearDown(ApprovalHistoryTest.java:50) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497) at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:36)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at
org.junit.runners.ParentRunner.run(ParentRunner.java:300) at
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497) at
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at
org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at
org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
You've annotated the wrong attribute:
#PersistenceContext(unitName = "Approval_History")
private Logger logger = LoggerFactory.getLogger(ApprovalHistory.class);
Should be:
#PersistenceContext(unitName = "Approval_History")
public EntityManager em;
The #PersistenceContext annotation injects an EntityManager into your code, which is created from the EntityManagerFactory associated with the persistence unit that you specify ("Approval_History" in your case).