RESTfull API using jersey -Getting HTTP Status 500 – Internal Server Error - jersey

I am new to Rest API web service. I have tired to create simple REST API using jersey Library. It is call the resource page. but its not return the value.
It shows:- HTTP Status 500 – Internal Server Error
plus warning message in console :- WARNING: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [316] milliseconds.
My Resource:
package com.msfathi.messenger.resources;
import java.util.List;
import com.msfathi.messenger.model.MessageModel;
import com.msfathi.messenger.service.MessageService;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
#Path("/messages")
public class MessageResource {
MessageService messageService=new MessageService();
#GET
#Produces(MediaType.APPLICATION_XML)
public List<MessageModel> getMessage(){
System.out.println("messageresource is called");
return messageService.getAllMessages();
}
}
I got That messageresource is called output in console, but i did not got return value
console:
WARNING: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [321] milliseconds.
Jan 09, 2021 6:21:39 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jan 09, 2021 6:21:41 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Jan 09, 2021 6:21:41 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in [3949] milliseconds
messageresource is called
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.msfathi</groupId>
<artifactId>messenger</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>messenger</name>
<build>
<finalName>messenger</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>
<!-- uncomment this to get JSON support
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>
-->
</dependencies>
<properties>
<jersey.version>3.0.0-M1</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.msfathi.messenger</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>

Related

I can't make reasteasy work with maven and wildfly

I've been trying hard during an entire week to make it work but there no way I could make wildfly work even with a simple rest hello world app...
Went through all Resteasy doc, wildfly resteasy examples, several tutorial, maven doc linked to wildfly and resteasy and still...
I use JDK 1.8, wildfly 10.x, and resteasy 3.0.19 (which is my wildfly default version).
It seems like wildfly just don't want to see the content of the war. I mean web.xml is ok but my classes are totaly transparent. I get classnotfound on my application class when trying to define resteasy servlet localy and just nothing when using wildfly builtin servlet.
Here are my last pom.xml, web.xml and one and only java class (I tried already with javax.ws.rs.Application class and annotation it's same result. I tried also with custom servlet mapping and all...).
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.me.test</groupId>
<artifactId>testrest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>testrest Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>jconsole</artifactId>
<version>jdk</version>
<scope>system</scope>
<systemPath>C:/Program Files/Java/jdk1.8.0_112/lib/jconsole.jar</systemPath>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.19.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>testrest</finalName>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
Web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Archetype Created Web Application</display-name>
<!-- this tells RESTEasy to load resource classes -->
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
and my only class :
package com.me.services;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
#Path("/hello")
public class HelloService {
#GET
#Produces("text/plain")
public String sayHello() {
return "Hello World";
}
}
And when I try to access my service once deployed I got :
http://localhost:8080/testrest/ : Hello world! (From my index.html file)
http://localhost:8080/testrest/rest : Not Found
localhost:8080/testrest/rest/hello : Not Found
When I check my deployment in wildfly i can see my application but no servlet in undertow...
As explained before I tried many things like when trying to declare my own servlet in web.xml it works but then it can't find the application class in the war though it's actually there... Really seems like Wildfly doesn't see anything appart from my web.xml :/
use http://localhost:8080/testrest/rest/hello/ and also add path to your sayHello method

How to deploy Spring Boot application on Google App Engine(GAE) using Eclipse IDE?

I've created a spring boot application, and I want to deploy it on Google App Engine(GAE). With reference to that following are the things I've done.
Created spring boot app
Added appengine-web.xml and web.xml under webapp/WEB-INF
Configured Project ID and Version details under Google app engine settings
install maven depencencies using Maven install
Now, when I try to run my application using spring boot or google web application, it gives tomcat connection error.
Following are the related files,
appengine-web.xml
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>appname</application>
<version>1</version>
<threadsafe>true</threadsafe>
</appengine-web-app>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>org.example.Application</param-value>
</context-param>
<listener>
<listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>metricFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>metricFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextAttribute</param-name>
<param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
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>org.example</groupId>
<artifactId>spring-boot-fundamentals</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.1.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-legacy</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<packaging>war</packaging>
</project>
Before Spring Boot, I used to deploy an application to GAE using Google plugin. But for Spring Boot application, it's completely different. Just add appengine-web.xml and web.xml files under webapp/WEB-INF folder and use "mvn appengine:update" to deploy the application.
You are missing a number of the steps required to convert a Spring Boot application for App Engine Standard. In your particular case you need to:
Use WAR packaging instead of JAR packaging
Remove the Tomcat Starter and add the javax.servlet-api
Add the com.google.cloud.tools App Engine plugin to pom.xml
Set the runtime to java8 in appengine-web.xml
Exclude the JUL to SLF4J Bridge to ensure full logging
Or you could simply base yourself on the configuration in this sample Spring Boot application.
I would go into more details but then I'd simply be rewriting the source material, which I encourage you to read.

Cannot run simple servlet on GlassFish-4

My simple REST based webservice does encounter a problem when I try do run it. It seems that the deployment succeeds, but when I access the servlet I get this error:
WARNING: StandardWrapperValve[MySimpleServer]: Servlet.service() for servlet MySimpleServer threw exception
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:662)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
My root pom.xml is very simple and just contains these dependencies and plugins:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
<build>
<finalName>MySimpleServer</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
<version>3.1</version>
</plugin>
</plugins>
</build>
The web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>MySimpleServer</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MySimpleServer</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Actually, it worked earlier today and I have not made any changes at all to the pom.xml file. Is it something with Glassfish4 server? I have made a clean build, redeployed the servlet, restarted GlassFish etc. Nothing helps.
I've had this problem when I've accidentally mixed Jersey / JAX-RS versions - IE having both Jersey 1 & 2 libs on the classpath.
I can't see how this happens with just the three dependencies in your pom, but I'm quite sure this is happening somewhere.
Looking at your stacktrace, I can see this is what's happening.
This is javax.ws.rs-api/2.0 UriBuilder.java
118 public static UriBuilder fromUri(String uriTemplate) {
119 return newInstance().uri(uriTemplate);
120 }
Which is exactly what you're getting - a call to UriBuilder.uri(String) on line 119.
Looking at the equivalent line numbers in the UriBuilder source from Jersey 1.8 and it's a Javadoc comment for a different method.
So, you've somehow got jax-rs 2 on your classpath and it's causing this problem.
Maybe you have it on a shared / common classloader, or a stray lib lying around.
UPDATE
Yes - glassfish ships with Jersey / JAX-RS libs.
See this question
As an aside - if you're able, I'd upgrade to Jersey 2.
Hope this helps
Will

Errors while calling mongo-jackson mapper from RESTEasy method

Been on this one for a few days now. I have a java servlet, built with maven that will be deployed to Jetty (an older version). It's a RESTful web service on Jetty built with RESTEasy and Jackson, and the Jackson Mongo Mapper to connect me to MongoDB.
I can run the application from maven/jetty just fine (using mvn jetty:run), and it returns JSON as expected for queries that don't use the Jackson Mongo Mapper/Jackson bit. When I send a request that triggers Jackson and the mapper, however, I first get this error:
java.lang.NoClassDefFoundError: org/codehaus/jackson/map/deser/std/StdDeserializer
When I submit a second time (and all subsequent requests), I get this error:
java.lang.NoClassDefFoundError: Could not initialize class net.vz.mongodb.jackson.JacksonDBCollection
As nearly as I can tell, I have all the dependencies set up correctly, although I'll include my web.xml and pom.xml at the end of the question. If it isn't a dependency, it's occurred to me that there might be some issue with how my bean (BillItem.class) is getting passed. I'm relatively new to Java so this could easily be a stupid mistake rather than something related to the specific stack I'm trying to implement...any ideas of what is going on?
Here's my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!--
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param> -->
<context-param>
<param-name>resteasy.resources</param-name>
<param-value>com.myproject.BillServer</param-value>
</context-param>
<context-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.myproject.Service</param-value>
</context-param>
<context-param>
<param-name>resteasy.resource.method-interceptors</param-name>
<param-value>org.jboss.resteasy.core.ResourceMethodSecurityInterceptor</param-value>
</context-param>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Here's my pom.xml:
<?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>
<groupId>com.myproject</groupId>
<version>0.0.1-SNAPSHOT</version>
<name>MyProject</name>
<artifactId>MyProject</artifactId>
<packaging>jar</packaging>
<properties>
<java.version>1.6</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Servlet API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<!-- Jetty -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>8.1.7.v20120910</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1-glassfish</artifactId>
<version>2.1.v20100127</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>2.3.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>2.3.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<version>2.3.4.Final</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.9</version>
</dependency>
<dependency>
<groupId>net.vz.mongodb.jackson</groupId>
<artifactId>mongo-jackson-mapper</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.9.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<!-- The maven app assembler plugin will generate a script that sets up the classpath and runs your project -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<assembleDirectory>target</assembleDirectory>
<programs>
<program>
<mainClass>com.MyProject.Main</mainClass>
<name>webapp</name>
</program>
</programs>
<useAllProjectDependencies>true</useAllProjectDependencies>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
And the last line of the following is the offending call that's throwing the error:
Mongo mongo = new Mongo(MONGO_PATH, MONGO_PORT);
DB db = mongo.getDB(MONGO_APPDB);
DBCollection collection = db.getCollection(MONGO_BILL_COL);
JacksonDBCollection<BillItem, String> coll = JacksonDBCollection.wrap(collection, BillItem.class, String.class);
This was some serious idiocy. I accidentally deleted 3 of the jackson dependencies when I was cleaning up my pom file.

org.springframework.web.servlet.DispatcherServlet not found with VMWare vFabric tc Server and maven

I know that there is a previously posted question that is very similar to this one. But the solution doesn't apply to my problem.
I'm trying to start a basic Spring project with Maven.
This is my 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>es.indra</groupId>
<artifactId>springappUV</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<org.springframework.version>3.1.1.RELEASE</org.springframework.version>
</properties>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
This is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>springappUV</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/app-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web-app>
I am using VMWare vFabric tc Server Developer Edition v2.6 (the one that comes with STS). When I run the webapp with it, I get the following error:
GRAVE: El Servlet /springappUV lanzó excepción de load()
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1043)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4957)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5284)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5279)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
06-jul-2012 14:06:56 org.apache.catalina.startup.HostConfig deployDirectory
I know it must have to do with the dependencies, but in the Maven dependencies the jar spring-webmvc-3.1.1.RELEASE.jar contains the class that the error says is missing.
So it seems that the server doesn't know that the library is there.
Does anyone know what could be happening?
Thanks!
In project options you should include Maven Dependencies to your Deployment Assembly
Project properties-> Deployment Assembly -> Add..
Java Build Path Entries -> Maven Dependencies
Finish
upd: Please also note that you should set packaging to war in your project pom.xml
<packaging>war</packaging> and then use Maven->Update Project.. if you are using eclipse maven plugin to update STS project periodically.
You must include maven dependencies in the deployment assembly - they are not being deployed to the webserver. That's how you fix that error in eclipse, I guess STS will be similar.

Resources