java.lang.NoClassDefFoundError: org/apache/cxf/jaxrs/model/doc/DocumentationProvider - spring

I am trying to integrate swagger. I am following steps as given here. application context and pom.xml is configured same.
when restarting tomcat getting this error.
2018-04-30 14:01:33 ERROR ContextLoader:351 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productAPIServer': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/cxf/jaxrs/model/doc/DocumentationProvider
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
I have included
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description-swagger</artifactId>
<version>3.1.7</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description</artifactId>
<version>3.1.7</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>3.1.7</version>
</dependency>
Changes in context xml file:
<bean id="jacksonJsonProviderFasterxml" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
<bean id="swagger2Feature" class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">
<property name="basePath" value="/staticdata-web-service"/>
<property name="license" value=""/>
<property name="licenseUrl" value=""/>
<property name="title" value="Static data web service"/>
</bean>
Added feature
<jaxrs:features>
<ref bean="swagger2Feature" />
</jaxrs:features>

You have a version mismatch. When you search on Maven for that class, you'll find that the package of the DocumentationProvider has changed from version 3.0.x to 3.1.x
org/apache/cxf/jaxrs/model/doc/DocumentationProvider
to
org/apache/cxf/jaxrs/model/wadl/DocumentationProvider
It's hard to tell where the mismatch is located without having insight into your entire build and package dependencies. But you may want to run
mvn dependency:tree -Dverbose
in your project folder to see which package versions come into question for raising your ClassNotFoundException.

use below dependency in your maven project to solve your issue,
<!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-rs-json-basic -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-json-basic</artifactId>
<version>3.4.3</version>
<scope>provided</scope>
</dependency>

Related

How to set primary rabbit template and rabbit connection factory

I am facing some errors in a spring boot project where I am using spring integration to connect to RabbitMQ. I am doing the configuration for RabbitMQ in XML files like this:
<!-- RabbitMQ configuration -->
<rabbit:connection-factory
id="rabbitConnectionFactory_2"
host="${queuing.events.host}"
port="${queuing.events.port}"
username="${queuing.events.username}"
password="${queuing.events.password}"
virtual-host="${queuing.events.virtual-host}"
publisher-returns="true"/>
<rabbit:template id="amqpTemplate_2" connection-factory="rabbitConnectionFactory_2" />
<rabbit:admin id="rabbitAdmin_2" connection-factory="rabbitConnectionFactory_2"/>
<rabbit:listener-container connection-factory="rabbitConnectionFactory_2" auto-startup="true" requeue-rejected="false" />
<bean id="rabbitListenerContainerFactory_2" class="org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory">
<property name="connectionFactory" ref="rabbitConnectionFactory_2"/>
</bean>
<!-- -->
But I am creating two of each component. How to set the primaries ones?
Now the problem comes here, I was using this version for spring cloud:
<spring-cloud.version>Dalston.SR2</spring-cloud.version>
And everything was working fine, but if I update the version to:
<spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
This error is coming:
Description:
Parameter 0 of method rabbitSender in org.springframework.cloud.sleuth.zipkin2.sender.ZipkinRabbitSenderConfiguration required a single bean, but 2 were found:
- rabbitConnectionFactory: defined in null
- rabbitConnectionFactory_2: defined in null
Action:
Consider marking one of the beans as #Primary, updating the consumer to accept multiple beans, or using #Qualifier to identify the bean that should be consumed
And the error comes because of this dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
If I remove this dependency the error is not coming.
You can find an example project to reproduce this scenario. In the pom file you'll see this:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.SR2</spring-cloud.version> <!-- it works with this version-->
<!-- <spring-cloud.version>Edgware.RELEASE</spring-cloud.version> --> <!-- doesn't work with this version-->
</properties>
<dependencies>
<!-- SPRING BOOT -->
<!-- it fails because of this dependency in that we are using Edgware.RELEASE version -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
...
https://github.com/fjmpaez911/spring-integration-zipkin-cloud
So I need to know how to set a primary configuration for RabbitMQ and in addition I think that could be an issue because this error only comes if I use this version Edgware.RELEASE
Am I missing something?
fran, in Edgware.RELEASE the <artifactId>spring-cloud-sleuth-zipkin</artifactId> will resolve Zipkin 2 dependencies try using <artifactId> spring-cloud-starter-zipkin-legacy</artifactId> instead
To define the primary connection factory for RabbitMQ in XML files, you can do something like this:
<!-- Here the primary connection -->
<bean id="rabbitConnectionFactory" primary="true" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
<constructor-arg value="${spring.rabbitmq.host}"/>
<property name="username" value="${spring.rabbitmq.username}"/>
<property name="password" value="${spring.rabbitmq.password}"/>
<property name="virtualHost" value="${spring.rabbitmq.virtual-host}"/>
</bean>
<!-- RabbitMQ configuration -->
<rabbit:connection-factory
id="rabbitConnectionFactory_2"
host="${queuing.events.host}"
port="${queuing.events.port}"
username="${queuing.events.username}"
password="${queuing.events.password}"
virtual-host="${queuing.events.virtual-host}"
publisher-returns="true"/>
<rabbit:template id="amqpTemplate_2" connection-factory="rabbitConnectionFactory_2" />
<rabbit:admin id="rabbitAdmin_2" connection-factory="rabbitConnectionFactory_2"/>
<rabbit:listener-container connection-factory="rabbitConnectionFactory_2" auto-startup="true" requeue-rejected="false" />
<bean id="rabbitListenerContainerFactory_2" class="org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory">
<property name="connectionFactory" ref="rabbitConnectionFactory_2"/>
</bean>

java.lang.NoClassDefFoundError:org/apache/commons/fileupload/FileItemFactoryin Spring MVC

I am trying to build a simple Spring MVC Web App with the functionality of file uploading.I got following error:
java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
After a quick search,all answers pointed to the missing of dependencies,but it seems not to be true in my case:
I have included the following code in pom.xml:
<dependencies>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
with commons.io-2.4.jar and commons.fileupload-1.3.1.jar added into lib folder.
One interesting thing I found was that whenever I deleted the code:
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>10000000</value>
</property>
<property name="maxInMemorySize">
<value>10000000</value>
</property>
</bean>
the web app works fine(of course I removed the form for file uploading as well. )
If you visit the Maven Central Repository and enter the search term:
fc:org.apache.commons.fileupload.FileItemFactory
then every released artifact available containing that class will be listed.
You will find commons-upload 1.3.1 in that list.
Therefore you need to double check your deployment to ensure that jar is present.
Tip: Use fc: to locate jars in Maven Central that contain a specific class.
try to update your jar version, for Example:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
We cann't find versions upper 1.3 on Apache and mvnrepository.com , but you can try this : https://repository.jboss.org/commons-fileupload/commons-fileupload/2.0.0-SNAPSHOT/
In fact, I encountered the same problem and now working fine with version 2.0 under SpringMVC framework.

Class 'org.springframework.http.converter.json.MappingJackson2HttpMessageConverter' not found

I am getting the following error in the servlet-context.xml. I am following the following tutorial to get this done.
Multiple annotations found at this line:
- Class 'org.springframework.http.converter.json.MappingJackson2HttpMessageConverter'
not found
- Class 'org.springframework.http.converter.json.MappingJackson2HttpMessageConverter'
not found [config set: myapp/web- context]
<!-- Configure bean to convert JSON to POJO and vice versa -->
<beans:bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
</beans:bean>
you have to add spring-web.jar in your classpath or if you are using maven then you should add the following dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>X.Y.Z.RELEASE</version>
</dependency>

getting error java.lang.NoClassDefFoundError: org/hibernate/validator/resourceloading/ResourceBundleLocator

I have a spring project in which i am using a validator like the following:
<beans:bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application"
p:fallbackToSystemLocale="false" />
<beans:bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<beans:property name="validationMessageSource" ref="messageSource" />
</beans:bean>
<annotation-driven validator="validator" />
<resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**" />
When i run the project i get the following BeanCreationException:
org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'validator' defined in ServletContext resource [/WEB-INF/spring/appServlet
/servlet-context.xml]: Error setting property values; nested exception is
org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException:
Property 'validationMessageSource' threw exception; nested exception is
java.lang.NoClassDefFoundError: org/hibernate/validator/resourceloading/ResourceBundleLocator
Here is my snippet of POM:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
<!-- Hibernate entity manager with JPA 2 support. -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.0.Beta2</version>
</dependency>
<!-- Hibernate’s implementation of JSR-303. -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
<!-- The JSR-303 Bean Validation API library. -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
Why i am getting this error?
Thanks
Your dependencies are OK. Based on the provided information the error should not appear.
So I suggest you to check your IDE and whether the hibernate-validator dependency is really on classpath. If you are using Eclipse with M2E, try to update your project:
Project (right click on project) > Maven > Update Project....
This might be a broken backwards compatibility issue: https://jira.springsource.org/browse/SPR-10466
I had a similar problem using hibernate 5.2.10.Final and hibernate-validator 6.0.2.Final (that package version doesn't seem to be in sync with the others). Turns out, hibernate-validator's groupId was changed from org.hibernate to org.hibernate.validator. Once I made that change, the error went away, however I am using Dropwizard and noticed that there may be a version conflict somewhere, so that's something to keep an eye on.
I also had this exact same problem, tried all sorts of combinations of JAR versions, different bean definitions, even customised class implementations. Turns out, I just had to clean the project and restart Eclipse. Problem solved, and lesson learnt!
Check your dependency
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.8.Final</version>
</dependency>
Is must be at the same version of your other Hibernate dependencies.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Just use following dependency, it will fix your issue as this dependency provides basic validation from get go similar to hibernate.

Missing Spring AOP libraries in STS

I'm getting my feet wet with Spring. I downloaded STS and I'm following basic examples from Spring in Action Second Edition. I'm stuck when trying to implement basic AOP and I guess I'm just missing some specific libraries in my project.
I say so because annotations like #Aspect are not recognized in my classes like also <aop:config> in my xml.
This are my Maven Dependencies:
junit-4.7.jar
spring-test-3.0.2.RELEASE.jar
spring-context-3.0.2.RELEASE.jar
spring-aop-3.0.2.RELEASE.jar
aopalliance-1.0.jar
spring-beans-3.0.2.RELEASE.jar
spring-core-3.0.2.RELEASE.jar
commons-logging-1.1.1.jar
spring-expression-3.0.2.RELEASE.jar
spring-asm-3.0.2.RELEASE.jar
log4j-1.2.14.jar
Please let me know what libraries I'm missing and where to find them.
Thank you!
EDIT:
The following:
<bean id="performancePointcut"
class="org.springframework.aop.aspectj.AspectJExpressionPointcut" >
<property name="expression" value="execution(* Performer+.perform(..))" />
</bean>
throws the following exception:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'performancePointcut' defined in file [C:\Users\Prova\Documents\STS\SpringIdol3\src\main\resources\META-INF\spring\spring-idol.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
DONE!
This aspectj-annotation-tutorial did the job with steps 1, 2, and 3.
It's been a fun Friday night....
Put these two dependencies in your pom.xml:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.11</version>
</dependency>
you may add maven dependencies:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>

Resources