SEVERE: MessageBodyWriter not found for media type=application/xml - jersey

I know this may sound like a duplicate of this or some others, but bear with me.
I have a very basic JAX-RS resource, have added all the required annotations that I saw in this tutorial I followed here.
But I keep getting HTTP Status 500 and the following log output in Eclipse's console.
Mar 18, 2021 1:35:23 AM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/xml, type=class com.varun.demorest.model.User, genericType=class com.varun.demorest.model.User.
Using Maven, but even after adding most suggestions I am finding on similar questions, I see that it was all mostly already included under
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
pom.xml:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.varun</groupId>
<artifactId>demorest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>demorest</name>
<build>
<finalName>demorest</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<jersey.version>3.0.1</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
My Model class:
User.java:
package com.varun.demorest.model;
import jakarta.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class User {
private String name;
private String phone;
public User() {
}
public void setName(String name) {
this.name = name;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getName() {
return name;
}
public String getPhone() {
return phone;
}
}
CustomResource.java:
package com.varun.demorest;
import com.varun.demorest.model.User;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
#Path("getUser")
public class CustomResource {
#GET
#Produces(MediaType.APPLICATION_XML)
public User getUser() {
System.out.println("getUser Called!");
User user = new User();
user.setName("Varun");
user.setPhone("xxxxxxxxxx");
System.out.println(user);
return user;
}
}
I am unexperienced in JAX-RS, so any help is much appreciated.
Using Java 11 and Tomcat 10.

as say #Paul Samsotha, it solve this problem for me, I append in pom.xml this:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>3.0.2</version>
</dependency>
and it fix problem.

I am on JDK 17 and Tomcat 10, faced the same issue. Adding the following dependencies worked for me to enable JAXB without any error. (If you don't have any of these - some or the other error would come)
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.0</version>
</dependency>

I was following the same tutorial and having the same issue, I fixed it by adding the following dependencies:
` <dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>3.0.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>3.0.2</version>
</dependency>
`

I have used the jaxb-runtime and jersey-media-jaxb jars which fixed the error.
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.0-M4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>3.0.4</version>
</dependency>

added #jakarta.xml.bind.annotation.XmlRootElement in pojo class.
and in pom.xml added below dependencies
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.0-M4</version>
</dependency>
this resolved issue.

was running a similar code in Eclipse 2022-03, ran into same error
fixed it with these three dependencies
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>3.0.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>3.0.2</version>
</dependency>
all before I was able to return Xml data,
I wonder why these works

Instead of using #XmlRootElement, use #jakarta.xml.bind.annotation.XmlRootElement
This is such a silly thing that solved my problem. This is so frustrating I spent hours solving this and this freaking small thing solved it. Please confirm if my answer helped you. Thanks.

Related

Newly generated Sprint Boot REST Application only returns 401

I have a newly created Spring Boot 3.0 application using Kotlin, which returns 401 on all HTTP calls.
MyApiApplication.kt
package com.my.app.api
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
#SpringBootApplication()
class MyApiApplication
fun main(args: Array<String>) {
runApplication<MyApiApplication>(*args)
}
TestController.kt
package com.my.app.api
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.time.LocalDateTime
#RestController
#RequestMapping("/api/test")
class TestController {
#GetMapping("/")
fun test(): LocalDateTime {
return LocalDateTime.now()
}
}
application.properties
server.port=6020
spring.datasource.url=jdbc:postgresql://localhost:6010/mydb
spring.datasource.username=mydb
spring.datasource.password=mydbpass
pom.xml
4.0.0
org.springframework.boot
spring-boot-starter-parent
3.0.0-SNAPSHOT
<groupId>com.datadriven.headless.api</groupId>
<artifactId>headless-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>headless-api</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<kotlin.version>1.7.20</kotlin.version>
<testcontainers.version>1.17.4</testcontainers.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>${testcontainers.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
<plugin>jpa</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<repositories>
...
</repositories>
<pluginRepositories>
...
</pluginRepositories>
"curl -v localhost:6020/api/test" returns always returns 401. What am I doing wrong?
You might be affected by this issue.
Take a look here and try to see if your logs match the logs of the ticket. I think the issue is that spring boot when it does not understand the request it sends back the error page but the error page is also behind security by default and can't be disclosed, so then spring boot gives a 401 response instead of the error page.
Also this ticket is the current open ticket from spring-boot team to handle the above issue
Adding the following class solved my problem:
MyAppApiConfig.kt
package com.my.app.api
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.config.annotation.web.builders.WebSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer
#Configuration
#EnableWebSecurity
class MyAppApiConfig {
#Bean
fun webSecurityCustomizer(): WebSecurityCustomizer? {
return WebSecurityCustomizer { web: WebSecurity ->
web.ignoring() // Spring Security should completely ignore URLs starting with /resources/
.antMatchers("/api/**")
}
}
}

Target Unreachable, identifier [tinyCalculator] resolved to null [duplicate]

This question already has answers here:
Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable
(18 answers)
How to properly install and configure JSF libraries via Maven?
(1 answer)
What exactly is Java EE?
(6 answers)
Closed 2 years ago.
I saw there is a lot of similar questions and answers for my situation, but the problem is none of them worked for me!
I'm trying to learn JSF and Spring boot and I've used some tutorials for them to manage this little simple code, but It does not work.
The problem is Eclipse knows my Managed Bean and it's properties in jsf page, and my page renders perfectly, but when I enter numbers and click on any of my command buttons, the error appears!
I thought maybe it cannot find target classes, so I tried to define it with
<build>
<outputDirectory>src\main\webapp\WEB-INF\classes</outputDirectory>
but nothing different happened! Would you please help me?
My pom.xml is:
<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>
<groupId>com.tebmahani</groupId>
<artifactId>Memorist</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax/javaee-api -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0.1</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<!-- <scope>provided</scope> -->
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-api -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.20</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-impl -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.20</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<!-- <scope>provided</scope> -->
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
<!-- <scope>provided</scope> -->
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.el/el-ri -->
<dependency>
<groupId>com.sun.el</groupId>
<artifactId>el-ri</artifactId>
<version>1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>9.0.35</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<outputDirectory>src\main\webapp\WEB-INF\classes</outputDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<failOnMissingWebXml>true</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
and my Managed Bean is:
package com.tebmahani.tinyCalculator;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
#Named("tinyCalculator")
#RequestScoped
public class TinyCalculator {
private double _param1;
private double _param2;
private double _result;
public TinyCalculator() {}
public TinyCalculator(double param1, double param2, double result) {
super();
this._param1 = param1;
this._param2 = param2;
this._result = result;
}
public double getParam1() {
return _param1;
}
public void setParam1(double param1) {
this._param1 = param1;
}
public double getParam2() {
return _param2;
}
public void setParam2(double param2) {
this._param2 = param2;
}
public double getResult() {
return _result;
}
public void setResult(double result) {
this._result = result;
}
public String add() {
this._result = _param1 + _param2;
return "";
}
public String subtract() {
this._result = _param1 - _param2;
return "";
}
public String multiply() {
this._result = _param1 * _param2;
return "";
}
public String divide() {
this._result = _param1 / _param2;
return "";
}
}
I'm going to write an answer that does not solve your problem but there is soo much wrong in your pom that it does not fit in a comment...
<outputDirectory>src\main\webapp\WEB-INF\classes</outputDirectory>
Using a src folder as an output folder is wrong... never do this. There is a target folder and if some things do not end up there for a weird reason, add them to the right target location, not a src folder. And checking if the classes were there or not was simple to do.
<!-- https://mvnrepository.com/artifact/javax/javaee-api -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0.1</version>
<!-- <scope>provided</scope> -->
</dependency>
This is the full blown java ee api, needed if you run a real java-ee server. It should then have scope of provided... Always. If you don't run a java-ee server but something like tomcat, it is waaay to broad There is a 'web profile' api but that should be for the light versions of real application servers, still not something like tomcat. So this api should be removed.
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<!-- <scope>provided</scope> -->
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-api -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.20</version>
</dependency>
So suppose the javaee api 8 jar is now present in your application. Then these two previous api's are already there, most likely in other versions (JSF on version 2.3, inject identical) which very likely cause problems.
<!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-impl -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.20</version>
</dependency>
There is a JSF 2.3 version and you have a 2.3 api. So you start your journey with 'old' versions already.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<!-- <scope>provided</scope> -->
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
<!-- <scope>provided</scope> -->
</dependency>
The libraries mentioned here are also already in the javaee api, so duplication as well. And even if you did not have the java ee api, the only one needed would be the cdi one. The others should always be provided.
<!-- https://mvnrepository.com/artifact/com.sun.el/el-ri -->
<dependency>
<groupId>com.sun.el</groupId>
<artifactId>el-ri</artifactId>
<version>1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>9.0.35</version>
</dependency>
This one duplicates several of the previous apis again... And since they have different maven groupId, artifactId they will be include. Implementation ok but for some api's you now have three jars...
So please start with cleaning all this up... Using 'joinfaces' to have all this done for you is a good thing!

Integrate kie-server into spring boot application

I want to integrate all the kie-server autoconfiguration (especially JBPM) in my spring boot application.
I added these gradle dependencies in a separate module of my project
dependencies {
compile group: 'org.kie', name: 'kie-server-spring-boot-starter', version: '7.29.0.Final'
compile group: 'xerces', name: 'xercesImpl', version: '2.12.0'
}
then I added the configuration properties suggested by this link
https://github.com/kiegroup/droolsjbpm-integration/blob/master/kie-spring-boot/kie-spring-boot-samples/jbpm-spring-boot-sample-basic/src/main/resources/application-postgres.properties
then I tryed to start the application, but I got this error:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in org.jbpm.springboot.datasources.JBPMDataSourceAutoConfiguration required a bean of type 'org.springframework.boot.jdbc.XADataSourceWrapper' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.boot.jdbc.XADataSourceWrapper' in your configuration.
The JBPMDataSourceAutoConfiguration class is linked below
https://github.com/kiegroup/droolsjbpm-integration/blob/master/kie-spring-boot/kie-spring-boot-autoconfiguration/jbpm-spring-boot-data-sources/src/main/java/org/jbpm/springboot/datasources/JBPMDataSourceAutoConfiguration.java
How can I correctly configure an embedded integration of jbpm/drools/kie in my existing spring boot project?
----------UPDATE-------------
After setting the property spring.jta.enabled = true, the exception changed in
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in org.jbpm.springboot.datasources.JBPMDataSourceAutoConfiguration required a bean of type 'org.springframework.boot.jdbc.XADataSourceWrapper' that could not be found.
The following candidates were found but could not be injected:
- Bean method 'xaDataSourceWrapper' in 'NarayanaConfiguration.GenericJdbcConfiguration' not loaded because #ConditionalOnProperty (narayana.dbcp.enabled=false) found different value in property 'narayana.dbcp.enabled'
- Bean method 'xaDataSourceWrapper' in 'NarayanaConfiguration.GenericJdbcConfiguration' not loaded because Ancestor me.snowdrop.boot.narayana.autoconfigure.NarayanaConfiguration did not match
- Bean method 'xaDataSourceWrapper' in 'NarayanaConfiguration.PooledJdbcConfiguration' not loaded because Ancestor me.snowdrop.boot.narayana.autoconfigure.NarayanaConfiguration did not match
- Bean method 'xaDataSourceWrapper' in 'AtomikosJtaConfiguration' not loaded because #ConditionalOnClass did not find required class 'com.atomikos.icatch.jta.UserTransactionManager'
- Bean method 'xaDataSourceWrapper' in 'BitronixJtaConfiguration' not loaded because #ConditionalOnClass did not find required class 'bitronix.tm.jndi.BitronixContext'
Action:
Consider revisiting the entries above or defining a bean of type 'org.springframework.boot.jdbc.XADataSourceWrapper' in your configuration.
Spring boot uses an embedded tomcat.
It took me a lot of time to make jbpm engine work as a spring boot application with an embedded tomcat, a lot of configs and hacks, especially for the controller 's password which can't be loaded from JKS
So, you need to declare JNDI lookup resources manually.
import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
import org.apache.tomcat.util.descriptor.web.ContextResource;
import org.kie.server.services.api.KieServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.jndi.JndiObjectFactoryBean;
import javax.naming.NamingException;
import javax.sql.DataSource;
#SpringBootApplication
public class KieServerApplication {
private static final Logger log = LoggerFactory.getLogger(KieServerApplication.class);
public static void main(String[] args) throws NamingException {
log.info("Starting things");
SpringApplication.run(KieServerApplication.class, args);
}
#Autowired
private Environment env;
#Bean
public TomcatServletWebServerFactory tomcatFactory() {
return new TomcatServletWebServerFactory() {
#Override
protected TomcatWebServer getTomcatWebServer(
Tomcat tomcat) {
tomcat.enableNaming();
return super.getTomcatWebServer(tomcat);
}
#Override
protected void postProcessContext(Context context) {
final ContextResource jbpmProjectDs = new ContextResource();
jbpmProjectDs.setName("jdbc/jbpmProjectDs");
jbpmProjectDs.setType(DataSource.class.getName());
jbpmProjectDs.setProperty("driverClassName", "com.mysql.cj.jdbc.Driver");
jbpmProjectDs.setProperty("url",env.getProperty("spring.mamodb.datasource.url"));
marjoryDs.setProperty("username", env.getProperty("spring.mamodb.datasource.username"));
jbpmProjectDs.setProperty("password", env.getProperty("spring.mamodb.datasource.password"));
context.getNamingResources().addResource(jbpmProjectDs);
final ContextResource narayanaTransactionManager = new ContextResource();
narayanaTransactionManager.setName("TransactionManager");
narayanaTransactionManager.setType(javax.transaction.TransactionManager.class.getName());
narayanaTransactionManager.setProperty("factory","org.jboss.narayana.tomcat.jta.TransactionManagerFactory");
context.getNamingResources().addResource(narayanaTransactionManager);
final ContextResource transactionSynchronizationRegistry = new ContextResource();
transactionSynchronizationRegistry.setName("TransactionSynchronizationRegistry");
transactionSynchronizationRegistry.setType(javax.transaction.TransactionSynchronizationRegistry.class.getName());
transactionSynchronizationRegistry.setProperty("factory","org.jboss.narayana.tomcat.jta.TransactionSynchronizationRegistryFactory");
context.getNamingResources().addResource(transactionSynchronizationRegistry);
}
};
}
#Bean(destroyMethod = "")
public DataSource jndiDataSource() throws IllegalArgumentException, NamingException {
JndiObjectFactoryBean bean = new JndiObjectFactoryBean();
bean.setJndiName("java:comp/env/jdbc/jbpmProjectDs");
bean.setProxyInterface(DataSource.class);
bean.setLookupOnStartup(false);
bean.afterPropertiesSet();
return (DataSource) bean.getObject();
}
#Bean
CommandLineRunner deployAndValidate() {
return new CommandLineRunner() {
#Autowired
private KieServer kieServer;
#Override
public void run(String... strings) {
log.info("KieServer {} started", kieServer);
}
};
}
}
** properties Config **
#transaction manager configuration
spring.jta.narayana.transaction-manager-id="1"
narayana.transaction-manager-id=1
narayana.dbcp.enabled=true
narayana.dbcp.maxTotal=20
spring.jta.log-dir=./target/tx-object-store
narayana.periodic-recovery-period=10
narayana.recovery-backoff-period=10
POM file just for dependencies:
<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>
<parent>
<groupId>org.kie</groupId>
<artifactId>kie-spring-boot-samples</artifactId>
<version>7.29.0.Final</version>
</parent>
<artifactId>kie-server</artifactId>
<name>KIE Server</name>
<description>KIE Server SpringBoot </description>
<properties>
<version.org.keycloak>5.0.0</version.org.keycloak>
</properties>
<dependencies>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-server-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description-swagger</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description-swagger-ui</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>net.minidev</groupId>
<artifactId>accessors-smart</artifactId>
</exclusion>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
<exclusion>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.kie.server</groupId>
<artifactId>kie-server-client</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_2.1_spec</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.narayana.tomcat</groupId>
<artifactId>tomcat-jta</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-transaction-spi</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>pull-parser</groupId>
<artifactId>pull-parser</artifactId>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</dependency>
<dependency>
<groupId>com.github.relaxng</groupId>
<artifactId>relaxngDatatype</artifactId>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.10</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.tomcat</groupId>
<artifactId>tomcat-jta</artifactId>
<version>5.9.0.Final</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.keycloak.bom</groupId>
<artifactId>keycloak-adapter-bom</artifactId>
<version>${version.org.keycloak}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<dependency>
<groupId>io.marjory</groupId>
<artifactId>model</artifactId>
<version>1.0.99-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.marjory</groupId>
<artifactId>marjory-jta</artifactId>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description-swagger</artifactId>
<version>${version.org.apache.cxf}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
<version>8.0.23</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-transaction-spi</artifactId>
<version>7.6.0.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<version>1.1.1.Final</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>pull-parser</groupId>
<artifactId>pull-parser</artifactId>
<version>2.1.10</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.8.17</version>
</dependency>
<dependency>
<groupId>com.github.relaxng</groupId>
<artifactId>relaxngDatatype</artifactId>
<version>2011.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<profiles>
<profile>
<id>mysql</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>QuickBuild</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<includes>
<include>com/marjory/kie/server/*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>go-to-hell</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Cheers,
just go to start.jbpm.org and
download ready made spring booy kie-server!

Only first request mapping resolves Java Spring Boot (circular view path)

I'm trying to map several request paths in my Spring Boot application. It's a RESTful web service but I wanted to have two views (main and help) for user interface. I've tried tweaking the names of the return string (ie. from "help.html to "help"), as well as cleaning my project and rebuilding, but I cannot figure why one view resolves and the other view does not and returns a circular path. I've also tried creating a separate HelpController and mapping it there. I don't see anything different I am doing between the two.
Here is my MainController.java:
#Controller
public class MainController {
#RequestMapping(value = "/help", method = RequestMethod.GET)
public String help(){
System.out.println("GET called on help page");
return "help.html";
}
#RequestMapping(value = "/main", method = RequestMethod.GET)
public String landing(){
System.out.println("GET called on index page");
return "landing.html";
}
}
My App.java:
#SpringBootApplication
#EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class App {
// private static final Logger logger = Logger.getLogger(App.class.toString());
public static void main(String[] args){
SpringApplication.run(App.class, args);
}
}
I put my two html templates in the resources/static directory:
But only one of these two paths resolve correctly. main.html looks great:
But help.html has a circular reference I cannot resolve or understand:
Here is my pom.xml (certain tags omitted for privacy):
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.2.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>dynamodb-local-oregon</id>
<name>DynamoDB Local Release Repository</name>
<url>https://s3-us-west-2.amazonaws.com/dynamodb-local/release</url>
</repository>
</repositories>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.derjust/spring-data-dynamodb -->
<dependency>
<groupId>com.github.derjust</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>4.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-dynamodb -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.11.125</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Gosling-SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>${aws-java-sdk.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>DynamoDBLocal</artifactId>
<version>${aws.dynamodblocal.version}</version>
</dependency>
</dependencies>
</project>
the simplest way to solve your issue is to change the mapping from /help to something else, or rename the static file help.html.
The reason for the circular dependency is because the view name help.html will again get mapped to your controller. Spring MVC uses a suffix to determine a mimetype of the response by default, this means that a method mapped to /help, will intercept the /help.html request as well

java.lang.NoClassDefFoundError: Could not initialize class com.datastax.driver.core.Cluster

I have a maven project A
pom.xml for the project A :
<dependencies>
<dependency>
<groupId>com.app.cops</groupId>
<artifactId>cassandra-logging</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
pom.xml of the project cassandra-logging:
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<version>3.9.0.Final</version>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
The cops-logging projecct has the following code :
CassandraCopsComponentLogger.instance = new CassandraCopsComponentLogger();
String hosts = CassandraClientUtil.getHost();
String localDC = CassandraClientUtil.getLocalDC();
Cluster cluster;
if (StringUtils.isNotEmpty(localDC))
{
cluster = Cluster.builder().addContactPoints(hosts.split(","))
.withCredentials(CassandraCopsComponentLogger.USER_NAME, CassandraCopsComponentLogger.AUTH_CODE)
.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.LOCAL_ONE))
.withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(localDC).build())).build();
}
else
{
cluster = Cluster.builder().addContactPoints(hosts.split(","))
.withCredentials(CassandraCopsComponentLogger.USER_NAME, CassandraCopsComponentLogger.AUTH_CODE)
.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.LOCAL_ONE)).build();
}
Session session = cluster.connect();
CassandraCopsComponentLogger.mappingManager = new MappingManager(session);
I keep on getting exception on the following line :
cluster = Cluster.builder().addContactPoints(hosts.split(","))
I have a unit test in cassandra-logging project which works fine with this code. But when I call the same code from project A I get the
java.lang.NoClassDefFoundError: Could not initialize class com.datastax.driver.core.Cluster
I was able to resolve this by downgrading the cassandra dependency version to <version>2.1.9</version>. Not sure how that helped but I was able to move forward.
Update the version of cassandra-driver-core and cassandra-driver-mapping to 3.3.0 - this worked for me:
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.3.0</version>
</dependency>
I ran into similar issue. The error i got was :
Factory method 'sqlSession' threw exception;
nested exception is java.lang.NoClassDefFoundError: com/datastax/oss/protocol/internal/SegmentCodec
relevant pom.xml segment:
<properties>
..
<oss-java-driver.version>4.9.0</oss-java-driver.version>
..
</properties>
..
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-core</artifactId>
<version>${oss-java-driver.version}</version>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-query-builder</artifactId>
<version>${oss-java-driver.version}</version>
</dependency>
Solution that worked for me : I have to explicitly declare dependency on native-protocol to override the version of native-protocol.
<properties>
..
<cassandra-native-protocol.version>1.4.11</cassandra-native-protocol.version>
..
</properties>
..
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>native-protocol</artifactId>
<version>${cassandra-native-protocol.version}</version>
</dependency>
Reference : https://community.datastax.com/answers/8185/view.html

Resources