Spring Data Cassandra ClassNotFoundException - cassandra

get this error when start spring boot application
my spring boot application
Spring Boot version 2.2.4
and cassandra version
spring-data-cassandra 3.0.1.RELEASE
this is my error
Caused by: java.lang.ClassNotFoundException: org.springframework.data.convert.CustomConversions$ConverterConfiguration
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 113 common frames omitted
and my config class
public class CassandraConfig {
#Bean
public CqlSessionFactoryBean session() {
CqlSessionFactoryBean session = new CqlSessionFactoryBean();
session.setContactPoints("localhost");
session.setKeyspaceName("mykeyspace");
session.setUsername("cassandra");
session.setPassword("cassandra");
session.setLocalDatacenter("dc1");
return session;
}
#Bean
public SessionFactoryFactoryBean sessionFactory(CqlSession session, CassandraConverter converter) {
SessionFactoryFactoryBean sessionFactory = new SessionFactoryFactoryBean();
sessionFactory.setSession(session);
sessionFactory.setConverter(converter);
sessionFactory.setSchemaAction(SchemaAction.NONE);
return sessionFactory;
}
#Bean
public CassandraMappingContext mappingContext(CqlSession cqlSession) {
CassandraMappingContext mappingContext = new CassandraMappingContext();
mappingContext.setUserTypeResolver(new SimpleUserTypeResolver(cqlSession));
return mappingContext;
}
#Bean
public CassandraConverter converter(CassandraMappingContext mappingContext) {
return new MappingCassandraConverter(mappingContext);
}
#Bean
public CassandraOperations cassandraTemplate(SessionFactory sessionFactory, CassandraConverter converter) {
return new CassandraTemplate(sessionFactory, converter);
}
}
how can in fix this error?

Those versions are incompatible. spring-data-cassandra had a significant breaking changes from the 2.2.x version to 3.x.x version.
To use the 3.x.x version of Cassandra, you will to upgrade spring to 2.3.x. Either that or you will need to downgrade to 2.2.x version of spring-data-cassandra.

i'm get a same exception,
when i upgrade the spring boot version, it's work!
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Related

Quarkus Unsatisfied dependency for type javax.ws.rs.sse.Sse and qualifiers [#Default]

I try to reproduce https://github.com/volkaert/events-sse-quarkus ; here is an extract :
#ApplicationScoped
#Path("/api-1.0/trevents")
public class SseRealTimeService {
private final Logger log = Logger.getLogger(getClass());
private long id;
private Sse sse;
private SseBroadcaster sseBroadcaster;
public SseRealTimeService(#Context Sse sse,final #Context HttpHeaders httpHeaders) {
this.log.debug(">>>>>>>>>>>>setSse :) " + sse);
this.log.debug(">>>>>>>>>>>>httpHeaders :) " + httpHeaders);
this.sse = sse;
}
...
And I get :
Caused by: javax.enterprise.inject.spi.DeploymentException:
Found 2 deployment problems:
[1] Unsatisfied dependency for type javax.ws.rs.sse.Sse and qualifiers [#Default]
- java member: org.avm.business.rest.api.SseRealTimeService#<init>()
- declared on CLASS bean [types=[org.avm.business.rest.api.SseRealTimeService, java.lang.Object], qualifiers=[#Default, #Any], target=org.avm.business.rest.api.SseRealTimeService]
[2] Unsatisfied dependency for type javax.ws.rs.core.HttpHeaders and qualifiers [#Default]
- java member: org.avm.business.rest.api.SseRealTimeService#<init>()
- declared on CLASS bean [types=[org.avm.business.rest.api.SseRealTimeService, java.lang.Object], qualifiers=[#Default, #Any], target=org.avm.business.rest.api.SseRealTimeService]
As far as I understood, it means it didn't find any class implementing Sse interface which could be injected.
My pom (extract dependencies node) :
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<!-- TESTS -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
I have seen this https://github.com/quarkusio/quarkus/issues/6515
but it says v1.5 solved it ; my quarkus version is 1.8.0 (<quarkus.platform.version>1.8.0.Final</quarkus.platform.version> in pom.xml).
I'm lost ... any idea ?

OmniFaces not destroying ViewScoped bean after closing tab/window

I have a simple jsf app with one Bean.
import org.omnifaces.cdi.ViewScoped;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Named;
import java.io.Serializable;
#Named
#ViewScoped
public class IndexMg implements Serializable {
List list;
#PostConstruct
public void init() {
list = new ArrayList();
list.add("as");
list.add("dsu");
}
#PreDestroy()
public void end() {
System.out.println("predestroy called");
}
}
according to this answer and conversation down this post and also OmniFaces documentation OmniFaces ViewScoped bean should invoke #PreDestroy function when I navigate away by GET, or close the browser tab/window but nothings happens until session destroy.
I'm using Wildfly 15 as Application Server and i can see activeViewMaps in sessions. Yoy can see sessions content here .
It's something like this :
com.sun.faces.application.view.activeViewMaps {1d31c745-c202-4256-a2c6-60035bfdd8e7={org.omnifaces.cdi.viewscope.ViewScopeStorageInSession=b557d2aa-ba35-4ff2-9f4e-3cc4ac312c9a}, ca02df9d-be65-4a75-a399-3df9eabbcfd3={org.omnifaces.cdi.viewscope.ViewScopeStorageInSession=aaef6a5a-d385-4e33-a990-200f94b67583}}
I opened multiple windows an closed them but non of them destroyed until session destroy(30 minutes later). What's wrong? did i forget anything?
this is my pom
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.3.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.enterprise/cdi-api -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0.SP1</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.omnifaces/omnifaces -->
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>3.2</version>
</dependency>
</dependencies>

Injecting Stateless EJB into Named Bean

following a tutorial and got stuck with an issue.
System: wildfly 10, maven project with multimodules, packaging: ear
EJB:
#Stateless
public class ToyService implements ToyServiceRemote, ToyServiceLocal {
...
}
INTERFACE:
#Local
public interface ToyServiceLocal {
...
}
BEAN:
#Named("toyProducts")
#RequestScoped
public class ProductBean {
#Inject
private ToyServiceLocal toyService;
#PostConstruct
public void initialize() {
toyList = toyService.getAllToys();
}
...
}
JSF:
<ui:repeat value="#{toyProducts.toyList}" var="toy">
...
</ui:repeat>
The application deploys, but when I try to open the page in browser I am getting:
ERROR [io.undertow.request] (default task-62) UT005023: Exception
handling request to /index.xhtml: javax.servlet.ServletException: Can
not set com.example.common.service.ToyServiceLocal field
shop.beans.ProductBean.toyService to
com.example.product.service.ToyServiceLocal$ToyServiceRemote$1303029808$Proxy$_$$_Weld$EnterpriseProxy$
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
wildfly-experiment | at
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
wildfly-experiment | at
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
wildfly-experiment | at
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
...
I found the "real" answer this time: since I am using multi module maven project, packaged as EAR (with some EJBs, a common JAR and the WAR file). All I had to do was to add scope provided in the WAR file (common is JAR and product in EJB)
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>product</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

Arquillian testing JSF with CDI - CDI Scope issue

We are in the process of migrating our JavaEE app from Weblogic 10.3.6 to Weblogic 12.2.1.2. As part of this migration we are changing our JSF managaged beans to use CDI annotations rather than the standard JSF annotations. #ManagedBean to #Named and javax.faces.bean.ViewScoped to javax.faces.view.ViewScoped. This has proved successful with only minor issues. However I am having a big issue trying to get our tests to run. The tests fail with the following error:
WebBeans context with scope type annotation #ViewScoped does not exist within current thread
I have tried multiple different containers (embedded and remote) but still get this same error. Any help would be much appreciated.
I am using Arquillian with the following pom.xml dependencies:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.12.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>arquillian-openejb-embedded</artifactId>
<version>7.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.0.13</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
BackingBean:
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import java.io.Serializable;
#Named
#ViewScoped
public class AnotherBean implements Serializable {
public String doTest()
{
System.out.println("test");
return "test";
}
}
TestBean
#RunWith(Arquillian.class)
public class TestAgain {
#Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class, "test.jar")
.addClass(AnotherBean.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
#Inject
AnotherBean anotherBean;
#Test
public void doTest()
{
Assert.assertEquals(anotherBean.doTest(), "test");
anotherBean.doTest();
}
}
UPDATE
If I change the #Deployment to:
#Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class, "test.jar")
.addClass(AnotherBean.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
I Get:
javax.enterprise.inject.UnsatisfiedResolutionException: Api type [AnotherBean] is not found with the qualifiers
Qualifiers: [#javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name : anotherBean, Bean Owner : [null]
We hat similar difficulties in testing #ViewScoped beans. We solved this by creating the bean with its injections in the test ourselfs.
The Bean instance itself ist created in the test and all dependencies are then inserted into that by using reflection. This works with beans, entitymanger etc
#RunWith(Arquillian.class)
public class ViewControllerTest {
#Inject private OtherBean otherBean;
private ViewController viewController;
#Deployment
public static WebArchive createDeployment() {
return WebArchiveFactory.getDefaultWebarchArchive();
}
#Before
public void setup() throws Exception {
viewController = new ViewController();
TestHelper.setFacesContext(); // provide FacesContextMock
TestHelper.inject(viewController, "otherBean", otherBean);
}
}
With TestHelper looking like this
public class TestHelper {
public static void inject(Object bean,
String fieldName,
Object fieldValue) throws Exception {
if (null == bean) {
throw new IllegalArgumentException("Bean must not be null");
}
Field field;
try {
field = bean.getClass().getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
log.log(Level.SEVERE, "Could not find field for injection: " + fieldName);
throw e;
}
field.setAccessible(true);
field.set(bean, fieldValue);
}
}
In the end I had to work around this problem with a good old fashioned hack. I found the source for org.apache.webbeans.container.BeanManagerImpl where the original WebBeans context with scope type annotation #ViewScoped does not exist within current thread comes from. I created this class within my test sources and I then made some changes to get around the problem.
Ultimately for my tests I don't care about the scope. I'm testing that the methods run and return the correct logic/data. So in the class it goes and checks what type of scope the bean is in and throws the exception. I simply checked if it was in Viewscoped and if so changed it to Dependent. This then allowed my tests to work.
Not the best solution but it works.

errors using xjc:superClass with XmlTransient annotation on super class with EclipseLink Moxy (jaxb 2.1 generated code)

i'm using xjc:superClass and an #javax.xml.bind.annotation.XmlTransient annotation on the super class.
i'm trying to switch over to Moxy and I get this error:
'Exception Description: Property [aspectStyleBlock] in class [com.aplia.q4.document.ValueStyle] references a class [com.aplia.q4.domain.AbstractBlock] that is marked transient, which is not allowed.
- with linked exception:
[Exception [EclipseLink-50057] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.JAXBException
' .
This all works fine under jaxb 2.1
If I remove the XmlTransient annotation on the superclass, I instead get this error:
'ava.lang.RuntimeException: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.NullPointerException]
....
'Caused by: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.NullPointerException]
at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:825)
at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:136)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:142)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:129)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:93)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:331)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at com.aplia.q4.service.hosting.impl.JAXBAdapter.<init>(JAXBAdapter.java:35)
... 27 more
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateChoiceCollectionMapping(MappingsGenerator.java:686)
at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateMapping(MappingsGenerator.java:434)
at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateMappings(MappingsGenerator.java:1996)
at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateMappings(MappingsGenerator.java:1957)
at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateProject(MappingsGenerator.java:193)
at org.eclipse.persistence.jaxb.compiler.Generator.generateProject(Generator.java:174)
at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:830)
at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:823)
... 41 more'
I have about 100 classes generated from schema (I don't control the schema). I tried to use http://jaxb2-commons.dev.java.net/basic/inheritance to implement an interface instead of xjc:superclass, but it will require me to list out all of my 100 classes, since bindings xpath can't match on multiple nodes. Reluctant to do so unless it is the only way to fix the problem.
This is blocking my efforts to convert to Moxy impl.
Details about my setup & why i chose to add the XmlTransient annotation:
from https://sites.google.com/site/codingkb/java-2/jaxb/jaxb-4
" causes #XmlValue is not allowed on a class that derives another class
You'd like your autogenerated JAXB classes to extend a common parent class... So you add something like this to your XSD:
Unfortunately, when you go to compile, you get an error message:
Exception in thread "main" com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
#XmlValue is not allowed on a class that derives another class.
The solution is to add an annotation to the base class:
#javax.xml.bind.annotation.XmlTransient
public class JAXBSuperClass
{
...
}"
My pom file (relevant parts only):
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1.13</version>
<scope>runtime</scope>
</dependency>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.4</version>
<executions>
<execution>
<id>generate-q4-document-jaxb</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<extension>true</extension>
<args>
<arg>-Xboolean-getter</arg>
<arg>-Xinheritance</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.5.3</version>
</plugin>
<plugin>
<groupId>com.nebulent.xjc</groupId>
<artifactId>boolean-getter</artifactId>
<version>1.0</version>
</plugin>
</plugins>
<schemaDirectory>${project.build.directory}/generated-sources/schema</schemaDirectory>
<bindingDirectory>${basedir}/src/main/resources/jaxb-bindings</bindingDirectory>
<forceRegenerate>true</forceRegenerate>
</configuration>
</execution>
</executions>
</plugin>
let me know if you need a schema, or any other info.
thanks in advance!
Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.
There are a couple issues related to your question:
Issue #1 - MOXy exception
Could you provide a small sample that demonstrates the issue that you are seeing?
UPDATE 1: I believe the issue that you are seeing is related to the following EclipseLink bug:
http://bugs.eclipse.org/378901
UPDATE 2: We have fixed the bug in both the EclipseLink 2.3.3 (available May 10 download) and 2.4.0 (available May 11 download) streams. You download these from the following location:
http://www.eclipse.org/eclipselink/downloads/nightly.php
Issue #2 - #XmlValue on a Subclass
The JAXB RI can not handle this use case:
Exception in thread "main" com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
#XmlValue is not allowed on a class that derives another class.
this problem is related to the following location:
at public java.lang.String forum10437666.Child.getValue()
at forum10437666.Child
at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:472)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:302)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1140)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:363)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at forum10437666.ValueDemo.main(ValueDemo.java:11)
EclipseLink JAXB (MOXy) can as long as the parent class does not map any of its fields/properties to XML elements:
Parent
The parent class only contains mappings to XML attributes.
package forum10437666;
import javax.xml.bind.annotation.XmlAttribute;
public class Parent {
private int id;
#XmlAttribute
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
Child
Child extends Parent and has a property mapped with #XmlValue.
package forum10437666;
import javax.xml.bind.annotation.XmlValue;
public class Child extends Parent {
private String value;
#XmlValue
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
ValueDemo
package forum10437666;
import javax.xml.bind.*;
import javax.xml.namespace.QName;
public class ValueDemo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Child.class);
Child child = new Child();
child.setId(123);
child.setValue("ABC");
JAXBElement<Child> je = new JAXBElement<Child>(new QName("child"), Child.class, child);
Marshaller marshaller = jc.createMarshaller();
marshaller.marshal(je, System.out);
}
}
Output
<?xml version="1.0" encoding="UTF-8"?>
<child xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="123">ABC</child>

Resources