I can't make reasteasy work with maven and wildfly - maven

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

Related

Unable to access the spring boot rest service from the WL server

I am very new to spring boot stuff. My question is about how to access a spring boot rest service deployed on weblogc server. I have successfully deployed (at least it seems from the WL console) the spring boot war file to the weblogic 12c container. But I am not able to access the service.
I am trying to use the following url to access:
http://host:port/myweb/resource/hello -- I am also not sure whether I should use WL server port on which the war is deployed or 8080 (default spring-boot port)
I have given all the code below. Am i missing anything? I would greatly appreciate any help
POM file:
<?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/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.0.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.demo</groupId>
<artifactId>SpringBootWL1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>SpringBootWL1</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<start-class>com.example.demo.SpringBootWl1Application</start-class>
</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-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Rest Controller:
#RestController
#RequestMapping("/resource")
public class ResourceController {
#GetMapping("/hello")
String home() {
return "Hello World, How are you!";
}
Spring Boot Application
#SpringBootApplication
public class SpringBootWl1Application extends SpringBootServletInitializer implements WebApplicationInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringBootWl1Application.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(SpringBootWl1Application.class);
}
}
Weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app
http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:context-root>/myweb</wls:context-root>
<wls:container-descriptor>
<!-- <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes> -->
<wls:prefer-application-packages>
<wls:package-name>org.slf4j.*</wls:package-name>
<wls:package-name>org.springframework.*</wls:package-name>
<wls:package-name>com.fasterxml.jackson.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
dispatcherServlet-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
Your configuration seems ok. The default port of Weblogic is 7001, and every web application is deployed using this port.
To verify the deployment you can access to the console from (http://host:7001/console) and go to the Deployments section, there you must find your application deployed and it must be in State OK. Your can check there your web application context there.
One thing I noticed is your file is called: Weblogic.xml, but it must be called weblogic.xml all lower case.
Let me know if it is not working.

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.

Got a 404 error on a simple rest service

i'm quite new to web developpement, I worked this summer on a web app on Spring, but the app was already set up, and was just doing some Java and AngularJS. But now i got some problem to start from scratch this type of application. I was trying to just test a simple web service, but can't reach the url I want, i get a 404 error. I'm working on Intellij with Tomcat 8.5.4 :
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>seb</groupId>
<artifactId>webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.10.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
application-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/context">
<jpa:repositories base-package="repository" />
<mvc:annotation-driven/>
<context:component-scan base-package="controller" />
</beans:beans>
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>springrest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springrest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Main.java
#SpringBootConfiguration
#EnableJpaRepositories("repository")
public class Main {
public static void main (String[] args) {
SpringApplication.run(Application.class, args);
}
}
StudentController.java
#RestController
public class StudentController {
private final StudentService studentService;
public StudentController(final StudentService studentService) {
this.studentService = studentService;
}
#RequestMapping(value = "/student", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void getSomeStudent() {
studentService.getSomeStudent();
System.out.println("Hello");
}
}
The url i'm trying to reach is : localhost:8080/webapp/student, but nothing happen, just have a 404 error. I guess i forgot something, but I looked at some tutorials and questions on the web, and can't figure how to fix my project. So if someone got some clues that can help me, that will be very helpful. Thanks by advance.
change #SpringBootConfiguration to #SpringBootApplication it configures following for you
#Configuration tags the class as a source of bean definitions for the application context.
#EnableAutoConfiguration tells Spring Boot to start adding beans based on classpath settings, other beans, and various property
settings. Normally you would add #EnableWebMvc for a Spring MVC app,
but Spring Boot adds it automatically when it sees spring-webmvc on
the classpath. This flags the application as a web application and
activates key behaviors such as setting up
#ComponentScan tells Spring to look for other components, configurations, and services in the the hello package, allowing it to
find the HelloController.
Since you are using spring-boot, add the following dependency,and remove web.xml where spring-boot automatically configures web dispatcher servlet for you
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
or you can still go ahead and configure one if you want.
Based on your initial settings, controller should be located at
http://localhost:8080/student (no 'webapp')
Well I stopped trying to deploy my app on tomcat, i'm just using spring now and i can reach my url. Anyway i will take deeper look at spring docs and tutorials, thanks for the different explications and link.
Use https://start.spring.io/ to create your Spring Boot Application project.
This will generate spring boot maven project for you.
Then add your StudentController there.
and afer that as #jahra specified, you have to trigger URL : http://localhost:8080/student to access your student webservice

404 Not Found Error in a simple Jetty/Maven Hello World webapp

I have followed the instructions to create a "Standard WebApp with Jetty and Maven" precisely as described on the eclipse wiki: http://wiki.eclipse.org/Jetty/Tutorial/Jetty_and_Maven_HelloWorld#Developing_a_Standard_WebApp_with_Jetty_and_Maven
However when I run the webapp (mvn jetty:run) and go to localhost:8080/hello-world/hello I end up at a "HTTP ERROR 404 Problem accessing /hello-world/hello. Reason: Not Found". I have read through documentation, looked at the wiki page's history, poked around other forums and stackoverflow threads, but can not find the answer to this seemingly simple problem. I will post my source, but it is literally the same as the tutorial.
Any help would be appreciated. I'd really like to start playing around with this technology but its disheartening to keep slamming into the same dead end.
(Please note: the first part of the tutorial to create "JettyMavenHelloWorld" work fine. My problem is with the second part, "JettyMavenHelloWarApp". This section is titled "Developing a Standard WebApp with Jetty and Maven")
JettyMavenHelloWarApp/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>hello-world</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Jetty HelloWorld</name>
<properties>
<jettyVersion>7.2.0.v20101020</jettyVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jettyVersion}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- This plugin is needed for the servlet example -->
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jettyVersion}</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution><goals><goal>java</goal></goals></execution>
</executions>
<configuration>
<mainClass>org.example.HelloWorld</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
JettyMavenHelloWarApp/src/main/java/org/example/HelloServlet.java
package org.example;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloServlet extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println("<h1>Hello Servlet</h1>");
response.getWriter().println("session=" + request.getSession(true).getId());
}
}
JettyMavenHelloWarApp/src/main/webapp/WEB-INF/web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<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_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>org.example.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/hello/*</url-pattern>
</servlet-mapping>
</web-app>
JettyMavenHelloWarApp/src/main/webapp/index.html
<h1>Hello World Webapp</h1>
Hello Servlet
The tutorial gives the incorrect url - your app context is still "/",
so the urls are http://localhost:8080 and http://localhost:8080/hello for the static and dynamic content, respectively.
The maven jetty plugin documentation does claim that the default context will be named the same as the artifactId in the pom.xml, but that doesn't seem to be working here.
I ran into the same issue and what worked for me was accessing the app like: http://localhost:8080/hello/index.jsp or http://localhost:8080/hello/index.html, whatever you're using html or js pages.
I think adding configuration to the jetty plugin definition in your pom should change the contextpath to hello-world:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jettyVersion}</version>
<configuration>
<webApp>
<contextPath>/hello-world</contextPath>
</webApp>
</configuration>
</plugin>
This is based on jetty version 9. See http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin for the configuration options.
I had the same problem with a basic configuration.
I wanted to redirect with Spring 3 MVC an error page with this configuration (in web.xml)
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/views/error.html</location>
</error-page>
I solve it by changing extension of error.html to error.jsp.
I think you don't run mvn package task before mvn jetty:run that is why jetty doesn't see any sources. Just run mvn package first.
Your servlet mapping is incorrect or insufficient.
<url-pattern>/hello/*</url-pattern> // does not respond to "/hello"
You need to add a mapping for the URL pattern "/hello"
<url-pattern>/hello</url-pattern>

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