I am new to Spring and I am starting to learn it from his website.
Understanding Java is not difficult to me, but I have trouble with the environment.
I followed this guide for using Spring Boot for creating a new project and everything went great
https://spring.io/guides/gs/spring-boot/
Now I would like to run this project from the Spring Tool Suite but I get this error when I try to run the same code on Pivotal or Tomcat server.
Failed to instantiate [org.springframework.boot.autoconfigure.web.HttpMessageConverters]: >Factory method 'messageConverters' threw exception; nested exception is java.lang.NoClassDefFoundError:org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverter
Any help from Spring developers for fixing my workflow?
When you try to run the project via a server, first build it using maven so that all the dependencies are downloaded. This helps to download MappingJackson2XmlHttpMessageConverter class also. After building it deploy the war you create into the server.
This class is added to spring from 4.1. You have to add
compile('org.springframework:spring-web:4.1.4.RELEASE')
for gradle, or
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
for maven.
Related
We have an application on java springboot which would interact with IoT devices via HTTP Rest API. However, there is an IoT device that communicates with the LWM2M protocol. So, I need to set up an LWM2M server and make the application an LWM2M client.
First I wanted to make a prototype on my local machine running application on Windows with eclipse ide. I tried importing the Leshan project from this link on eclipse workspace. However when maven clean install, it is not creating a jar file for every project. Attaching the result at eclipse console, when I do maven clean install..
My ask is:
Am I going the right way, in order to implement the LWM2M protocol locally?
How to resolve all jars not creating with Maven clean Install.
Our commercial LWM2M offering that is part of Cumulocity IoT in fact is a Spring Boot application which includes Leshan. So you are definitely on the right track.
While I am not able to disclose internals, I am happy to provide you some pointers how to get this flying.
In your pom.xml, declare the needed Leshan dependencies, for example:
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-core</artifactId>
<version>2.0.0-M9</version>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-server-core</artifactId>
<version>2.0.0-M9</version>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-server-cf</artifactId>
<version>2.0.0-M9</version>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-server-redis</artifactId>
<version>2.0.0-M9</version>
</dependency>
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>californium-core</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>scandium</artifactId>
<version>3.7.0</version>
</dependency>
I assume you know how to set up a Spring Boot application using maven. If not, this tutorial shows precisely how it can be done.
In your spring boot application you then can construct a LeshanServer object and accept LWM2M traffic. Have a look at the leshan-server-demo maven module in the Eclipse Leshan source code on how to do that.
Questions about build issues get much better help and answers, if you use Eclipse/Leshan - github issues. Not all open-source projects are watching stackoverflow and so you can get a "first hand first class" answers only there.
I have skipped the integration testing by commenting its dependency in the pom file. Then all other modules got compiled.
I try to make a java 15 maven project of a jaxws webservice using a embedded tomcat 10.
My current project is on https://github.com/BeRoots/MeteoWS/tree/master/src/main/java
I'm not sure it's a good idea to make this project using the cargo-maven2-plugin instead of building this project from an Axis2 or CXF Java-First SOAP archtype. But I want to preserve this way if it's acceptable. More informations about this choice are welcome ;)
To explain my actual problem. I have an error when I run maven:build with the error:
SEVERE: Error configuring application listener of class com.sun.xml.ws.transport.http.servlet.WSServletContextListener
java.lang.NoClassDefFoundError: jakarta/servlet/ServletContextAttributeListener
If someone have an idea. Thanks in advance
We just faced the same problem and the solution was adding jakarta.servlet-api to the project:
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
</dependency>
After a lot of searchs. I finally find a good answer about server uses. It explain that tomcat isn't a good server for this kind of project.
Difference between an application server and a servlet container?
and
enter link description here
So I choose to abord this maven project type to recreate a new one using glassfish.
I am setting up websockets with my Java j2ee servlet application. I was able to write the entire code and got the websockets working using following maven configuration -
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
My implementation does not work without <scope>provided</scope> and gives handshake exception: 404 not found.
Now, when I deploy my application on dev machines using travis, it gives exception while creating a build, and throws Java exception that ServerEndpoint class not found. I am assuming that it is because since scope is provided, Travis is not downloading the required jars while building a build on travis.
How do I avoid this, and ensure that we are able to work on local as well as deploy our builds via travis.
I created a Maven project in Eclipse using the webapp artifact and put the following lines in the .pom file upon reading an online tutorial.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
In the tutorial however, the version is 2.5.6. I replaced it with 3.0.5.RELEASE considering its the latest version.
But for this version eclipse is giving out an error
Missing artifact org.springframework:spring:jar:3.0.5.RELEASE:compile
What does this mean ? Can I add the required jar files to a lib folder and ask .pom file to take it from there as its being done in another tutorial on spring source website that uses Ant ?
Also Maven projects come with a different directory structure and seems to be doing much more than what Ant does in the spring source tutorial.
I am completely new to maven. in fact only a beginner in developing web applications using java. I did some tutorials from spring source and could deploy and run a spring mvc hello world app on apache tomcat. For this I used Ant and found it a great tool. But as I checked-out some example apps from spring source repo and it seems that Maven is more preferred and powerful than Ant. I am finding it a bit difficult to understand though.
Thanks
In version 3, Spring no longer provides the all-in-one Spring jar.
Note: The spring.jar artifact that
contained almost the entire framework
is no longer provided.
Source:
2.4 New module organization and build system
Depending on your project needs, use
<dependency>
<groupId>org.springframework</groupId>
<artifactId>${artifactId}</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
where ${artifactId} may be e.g.
spring-context (IOC core, standard ApplicationContext implementations)
spring-orm (ORM technologies: Hibernate, JPA, (I|My)Batis)
spring-webmvc (The Spring Web MVC framework)
spring-aop (Aspect-Oriented Programming support)
etc.
The selected dependencies will pull in their required libraries as transitive dependencies, so you usually just need the "most exotic technology". E.g. if you select Spring MVC and Spring ORM, you also get AOP, TX, Context, Web etc.
Reference:
Obtaining Spring 3 Artifacts with
Maven
In Spring 3.x they remove they removed this artifact. Now you have to declare dependencies on separate modules of Spring, such as
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
and so on.
Also see spring 3.0.5 library jars for the list of modules and description of dependencies between them.
Is there a tutorial somewhere which shows how to use spring framework with maven instead of ant? This one seems very good but it's all built with ant.
EDIT
I really don't know which answer to accept both are valid. I'll wait for some time let the community decide
Basically, the build.xml of the tutorial has 3 main targets :
build the application
deploy it on Tomcat server
Unit testing using a in-memory database (hsqldb)
Regarding the first point, you will just need to create a war project on Maven. As you told in your comment, you are already using Maven in anothers projects, so I don't think it will cause you lots of troubles. You will just need to add the Spring dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.2</version>
</dependency>
The second part concerns the deployment on Tomcat. Just use the cargo plugin for that.
For the last point, you will just need to add the HSQLDB dependency in your pom.xml:
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
<scope>test</scope>
</dependency>
Then, you will have to instanciate the database in one of your JUnit test case...
If you already know maven, then you can quickly start working with spring using this archetype
appfuse-basic-spring
Note that it sets everything up for Spring MVC, Spring and Hibernate so you should remove unnecessary files. Still, it's a great start.
If you don't know much about maven templates check this URL that explains how to use archetypes. An archetype is basically a project template.
The complete list of templates can be found here.
The Spring 3.0 samples are Maven based:
https://src.springframework.org/svn/spring-samples/mvc-basic/trunk/
https://src.springframework.org/svn/spring-samples/petclinic/trunk/
https://src.springframework.org/svn/spring-samples/spring-travel/trunk/