jersey with spring-boot 1.5.14 not working - rest

i am trying to make a jersey jax-rs rest project with spring-boot 1.5.14.
i have used spring jersey starter in dependency. but not working.
Please see my pom beolow.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.14.BUILD-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependences>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
</dependences>
Its not working. #Path #Get those all jax-rs anotation is not resolved.
i have added
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
</dependency>
then it is resolved. another issue has come.
register(RequestContextFilter.class); is not solved.
then i added---
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.24.1</version>
</dependency>
now it is solved but new error comming at runtime.
org/jvnet/hk2/spring/bridge/api/SpringBridge class def not found.
again i have added---
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>spring-bridge</artifactId>
<version>2.2.0-b14</version>
</dependency>
now different error has come---
org/glassfish/hk2/api/ServiceLocatorFactory$CreatePolicy class def not found.
again i have added.
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-api</artifactId>
<version>2.1.9</version>
</dependency>
now it is giving----
org/glassfish/hk2/utilities/binding/AbstractBinder class def not found
i have added h2k api
again it is giving
java.lang.NoClassDefFoundError: org/glassfish/hk2/api/ServiceLocator.
i upgraded hk2 api version . then comming class not found jersey.repackaged.com.google.common.base.Function
i added
<dependency>
<groupId>org.glassfish.jersey.bundles.repackaged</groupId>
<artifactId>jersey-guava</artifactId>
<version>2.25.1</version>
now t last it is giving-"No generator was provided and there is no default generator registered-IllegalArgs exception.
if i ad jeresy all. then it is throwing no implementation found for hibernate validator

Probably because you're using BUILD-SNAPSHOT for the Spring Boot parent version. If you're going to use a snapshot version, then you need to configure a snapshot repository in your pom. That's why the Jersey starter dependency can't be resolved. What you want to use is the RELEASE version. All Spring release version end with this suffix.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.14.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

Related

Mongo java driver upgrade from 3.12.1 to 4.2.3 throwing method/class not found execptions on deployment

I have java application based on mongo server 4.2 and component versions are as follows
spring-boot 2.2.5.RELEASE
spring-data-mongodb2.2.5.RELEASE
mongo-java-driver3.12.1
I updated spring boot to 2.5.8 hence made few changes to update dependencies as follow
spring-boot2.5.8
spring-starter-parent2.5.8
spring-data-mongodb 3.2.3
mongodb-driver-core 4.2.3
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>4.2.3</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.2.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.8</version>
</dependency>
As I used newly added
**import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;**
i.e mordern API using mongo-java driver 3.12.1 I updated to mongodb-driver-sync 4.2.3
I resolved all compilation errors but on deployment got errors like method not found for getSrvHost() on further debugging found that old dependency of mongo-java-driver 3.3.0 was already present in project
I excluded that dependency and above issue got resolved now no old dependency is present but still getting following error without using legacy API approach
java.lang.NoClassDefFoundError: com/mongodb/MongoClient
Caused by: java.lang.NoClassDefFoundError: com/mongodb/MongoClient
Completely stuck at this point in driver and spring upgrade process, without using com.mongodb.MongoClient in entire project it is throwing error on deployment.
It's recommended use spring-boot-starter-parent as <parent> to use compatible versions.
Just add the spring-boot-starter-data-mongodb dependency and it has all the necessary MongoDB drivers.
Remove from pom.xml: spring-data-mongodb, mongodb-driver-core, spring-starter-parent
Note: Always use the last version, since 2.5.8 has 3 vulnerabilities
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/>
</parent>
...
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
</dependencies>

Eclipse with Maven plugin does not work with latest revisions, but works with older ones

I have a simple project that uses Spring AOP. It uses annotation from AspectJ. The project is in Maven and it compiles ok with aspectjtools-1.7.4. With aspectjtools-1.8.9 it fails to see accept annotation #Aspect imported from org.aspectj.lang.annotation.Aspect. The same project gives no problems with Gradle and same JARs.
Why would my code not work with latest revision of AspectJ, but works ok with older one?
I am attaching 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>aspectjproblem</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>aspectjproblem</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<!-- WITH 1.8.9: FAILS to see org.aspectj.lang.annotation.Aspect -->
<!-- <version>1.8.9</version> -->
<!-- WITH 1.7.4: SEES OK: org.aspectj.lang.annotation.Aspect -->
<version>1.7.4</version>
</dependency>
</dependencies>
</project>
I guess it must have something to do with compliance-levels or similar things. Can anyone point me in the right direction? Many thanks.
It took me a while to understand what was the issue. I tried moving to Java8 and I played with dependencies. The problem I had was:
- Invalid LOC header (bad signature)
What means I guess Maven downloaded a corrupted file. I deleted it from repo (e.g. C:\Users\$USER.m2\repository\org\aspectj\aspectjtools ), updated maven and all started working again.

How can I specify the spring-data-mongodb version using spring-boot?

I want to use the latest version of spring-data-mongodb, in order to use the full text search feature, but I don't know how I can specify this using the spring-boot-starter-data-mongodb dependence.
You can read here: maven repository that the spring-data-mongodb version is not specify.
This is my pom file:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Boot Rest -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<!-- Spring Boot Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Spring MongoDB integration -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
Spring Boot defines all its dependencies and dependency versions in the spring-boot-dependencies project. This project only contains a pom with only dependencies and versions as properties.
Spring Data releases all of its compatible releases in a so called release train and this makes sure that all dependencies of that version will work together.
When you take a closer look a the pom you will see a maven property named spring-data-releasetrain.version and for the upcoming Spring Boot 1.2 it points to the latest release train version Evans-RELEASE. The 1.1.7 version points to the previous version Dijkstra-SR4. I would suggest an upgrade from 1.1.6 to 1.1.7 just in case.
You're project already has the spring-boot-starter-parent project as its parent so in theory upgrading the Spring Data versions should be as easy as overriding the specified property.
<properties>
<spring-data-releasetrain.version>Evans-RELEASE</spring-data-releasetrain.version>
</properties>
As mentioned earlier the use of the release train is preferred as this will make sure you get all the compatible versions.
You can find that mongodb dependency in the parent project pom file
/../.m2/repository/org/springframework/boot/spring-boot-dependencies/2.3.0.RELEASE/spring-boot-dependencies-2.3.0.RELEASE.pom
That file defines all the dependency version for other libs SpringBoot use
<properties>
<activemq.version>5.15.12</activemq.version>
<antlr2.version>2.7.7</antlr2.version>
...
<mongodb.version>4.0.3</mongodb.version>
...
</properties>
So if you want to use different version for mongodb, define a properties in your pom file to override the default one like (I think this will only work if you use spring-boot-starter-parent as parent )
<properties>
<mongodb.version>3.11.2</mongodb.version>
</properties>
Answer by #sendon1982 worked for me. Here is an example of my POM.XML. I am adding it as an answer here because I could not paste in my pom file as a comment to sendon1982 answer...
<?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.3.3.RELEASE</version>
<relativePath/>
</parent>
<groupId>test.barry</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<start-class>test.barry.Main</start-class>
<mongodb.version>4.1.0</mongodb.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.1.0</version>
</dependency>
</dependencies>
</project>

JSF2.2 in eclipse on wildfly8.1

I have a project created from some maven archetype, dont remmebrer realy which one. I use maven and Eclipse Kepler.
The project is deployed on Wildfly8.1 server
In the project facests I have JSF 2.0 and when I try to change the facet to JSF 2.2 I get the massege "Cann not change version of facet JavaServerFaces ..."
Do I have to change something in my maven pom file?
Here is my maven pom :
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>ypay</artifactId>
<groupId>si.arctur</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>ypay-web</artifactId>
<packaging>war</packaging>
<name>ypay Web module</name>
<dependencies>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0</version>
</dependency>
<!-- Dependency on the EJB module so we can use it's services if needed -->
<dependency>
<groupId>si.arctur</groupId>
<artifactId>ypay-ejb</artifactId>
<type>ejb</type>
<scope>provided</scope>
</dependency>
<!-- Import the JAX-RS API, we use provided scope as the API is included
in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the CDI API, we use provided scope as the API is included
in JBoss AS 7 -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JPA API, we use provided scope as the API is included
in JBoss AS 7 -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JSF API, we use provided scope as the API is included
in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.faces</groupId>
<artifactId>jboss-jsf-api_2.2_spec</artifactId>
<version>2.2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>1.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<!-- Java EE 6 doesn't require web.xml, Maven needs to catch
up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
You don't mention which Eclipse plugins you use. Assuming you have a current version of JBoss Tools, the facets should be set correctly when first importing the Maven project into Eclipse, depending on the POM dependencies.
In your POM, there's a mixture of Java EE 6 and 7 dependencies, which might be causing the problem.
Try deleting the javax:javaee-api:6.0 dependency - you have indidual Java EE 7 APIs further down in your POM -, then run Maven | Update project in Eclipse.
If that does not help, delete the project from the workspace, delete all Eclipse metadata from the file system (.project, .classpath,. settings) and re-import the project.

Really painful to run GWTP in Maven

I've been struggling all day to run GWTP with Maven, essentially I created a GWTP gwt application using the Eclipse plugin. And added a simple welcome presenter. Tried it without maven and it works well running from eclipse.
However when I convert it to a maven project (I'm using m2eclipse plugin) everything breaks. So I added the required dependencies and the gwtp dependency:
<dependency>
<groupId>com.google.gwt.inject</groupId>
<artifactId>gin</artifactId>
<version>1.5.0</version>
</dependency>
<!-- MVP component -->
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-all</artifactId>
<version>${gwtp.version}</version>
</dependency>
However when I try to run it I get this error:
Caused by: java.lang.RuntimeException: Deferred binding failed for 'com.google.gwt.event.shared.EventBus' (did you forget to inherit a required module?)
Any ideas why its quite hard to make GWTP with maven.
I think you might be missing the gwt-user dependency. Here is my maven pom.xml for an GWTP project:
<properties>
<gwtVersion>2.4.0</gwtVersion>
<gwtp.version>0.7</gwtp.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-mvp-client</artifactId>
<version>${gwtp.version}</version>
<scope>provided</scope>
</dependency>
<!-- Dispatch component -->
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-dispatch-client</artifactId>
<version>${gwtp.version}</version>
<scope>provided</scope> <!-- Remove for GWTP 0.5.1 and earlier -->
</dependency>
<!-- Tester component -->
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-tester</artifactId>
<version>${gwtp.version}</version>
<scope>test</scope>
</dependency>
In case you use the newest gwtp 0.7 be aware that they switched from the depreciated classes in com.google.gwt.event.shared to com.google.web.bindery.event.shared.
See here for more details.