404 error springboot restcontroller requestmapping - spring

I have a simple web application with springboot (netbeans 8.2), but resource mapping does not work, I have 2 days with the problem. any ideas?
ApplicationContext://///////////////////////////////////////////////
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/springXML8"/>
WEB.XML ////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>example</display-name>
<absolute-ordering />
<servlet>
<servlet-name>ServletCentral</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletCentral</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
ServletConfig:////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- paquete a escanear en busca de componentes -->
<mvc:annotation-driven/>
</beans>
Application://////////////////////////////////////////////////////////////
#SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
Controller:///////////////////////////////////////////////////////////////
#RestController
public class controller1 {
#RequestMapping("/")
public String hello(){
return "Lain love this service";
}
}
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>beans</groupId>
<artifactId>beans</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<name>SpringXML8</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</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-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Ok.
In itself what is your problem? How u are testing? Are you using postman, soap ui?
Based on your mapping your "url-pattern"/* "url-pattern" in web.xml is empty, so you donĀ“t need anymore in your URL Request. But you have little issues. Why do you have two Spring appCtx (ApplicationContext & ServletConfig)??
You do not provide more information. I don't know if you are trying to raise a Tomcat server or simple spring boot server default. You could stay just with ServletConfig, you shouldn't have -Context path="/springXML8"-
You could replace this with a #ResquestMapping global in your RestController. i.e.
#RestController
#RequestMapping("initialLoginOrSpringXML8")
public class PersonalController {
#RequestMapping("/getHello")
public String hello(){
return "Lain love this service";
}
}
Besides I suggest to add some word in your local #RequestMapping by method.
Remember if you use #RequestParams or #PathVariable, you must enter them especially depending on the test client you are using. As well as the type of request Http

#Diego Caballero
There are many options for which you have this error. The most common is a bad mapping of the URL.
The server may be confused by the 2 settings, it may not know which context path to respect. Verify the URL you are using, try different options, combinations.
Change
<url-pattern>/*</url-pattern>
to
<url-pattern>/</url-pattern>
Currently, your mapped DispatcherServlet is marked as handling all requests because of /*. This means that it will also attempt to handle a request dispatched to /WEB-INF/*** It obviously doesn't have a handler for that and will fail.
The pattern / is special in that it is the default fallback if no other pattern matches. If there's a Servlet that maps to the request path, that Servlet will be chosen before your mapped DispatcherServlet. (This maybe is your case).
Try to log everything you can. Use level of info, error and debug, of log4j. Also try to read the server logs (this is located in the folder where you downloaded it). Not only the console of your actual IDE.
Verify if you are deploying correctly the application. Maven cycle, etc. WAR or JAR?
Are you using the correct domain? localhost? or maybe is an ip or a diffente domain setted in the server options deploy
I hope it was a little help. Regards

Related

Launch Spring web application using Spring Boot

I am trying to launch an existing web application using Spring Boot, without changing my existing application at all and keeping the spring-boot specific stuff in a separate module. I have the following maven structure:
parent
web-app
boot-app
I want to launch the web-app from the boot-app.
My boot module
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>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Web Application -->
<dependency>
<groupId>my.group.id.</groupId>
<artifactId>web-app</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>classes</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.2.5.RELEASE</version>
</plugin>
</plugins>
</build>
</project>
Application.java:
#EnableAutoConfiguration
#ImportResource("classpath:WEB-INF/myApp-servlet.xml")
public class Application extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
My web module
Structure:
src/main/
java/ --> Rest Endpoints etc.
webapp/ --> web resources, only important files shown
WEB-INF/
myApp-servlet.xml
web.xml
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>
<artifactId>web-app</artifactId>
<packaging>war</packaging>
<name>some-name</name>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
</plugins>
</build>
</project>
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 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>My Web App</display-name>
<!-- Servlet Configuration -->
<servlet>
<servlet-name>myApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myApp</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
myApp-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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="some.corp.name.space"/>
<mvc:annotation-driven />
</beans>
My Problem
When I run Application.java I get the following error:
Caused by: java.io.FileNotFoundException: class path resource [WEB-INF/myApp-servlet.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
... 24 more
From what I can see, this is because the maven-war-plugin only includes classes in the jar it creates and does not include the webapp directory.
My Question
Is there any way for me to achieve this, with or without the maven-war-plugin?
The most important thing for me is to have the boot-app as a separate module.

No mapping found for HTTP request with URI [/MyTesting/] in DispatcherServlet with name 'mvc-dispatcher'

I am new to spring mvc and Maven. I am trying to get a simple hello world example working. I don't see where I am going wrong it should be straight forward. I am using Maven 3, Eclipse Kepler, Tomcat 6 on a MAC OS.
Can Someone please see the below code and see what is wrong? When I hit localhost:8080/MyTesting I expect to get my welcome file on browser but I get this on the browser:
HTTP Status 404 -
type Status report
message
description The requested resource is not available.
on Eclipse console I get:
WARNING: No mapping found for HTTP request with URI [/MyTesting/] in DispatcherServlet with name 'mvc-dispatcher'
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>MyTesting</groupId>
<artifactId>MyTesting</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<spring.version>3.1.1.RELEASE</spring.version>
</properties>
<dependencies>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>
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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>MyTesting</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
mvc-dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<context:component-scan base-package="main.com.mytesting" />
<bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
Start from this example from Spring developers and tweak it for yourself. It uses the newer, simpler Java Config (annotation-based) configuration.
If you still want to debug your current code, can you push it to github? Your requestMapping in the controller may not be right.
From your post I did not saw any controller configuration, and the error 404 means the required resource is not there.
There are two ways to develop Spring web MVC projects annotation based or programatically. This is a tutorial on the programatic approach, and this is a tutorial on the annotation based approach.
I think you don't create controller for dispatcher map.
I found this tutorial very helpful about create spring mvc.
Thanks Guys,
Its all good now after wasting a few hours of my dev time. I actually had a typo in my folder structures. My folder structure was main.com.mymesting.controllers hence the component scan was failing. I changed it to main.com.mytesting.controllers. It works fine now.
Check your spring configuration file and folder structure "src/main/java"
<context:component-scan base-package="com.wenzinsapp.testapp.controller" /> is resembles as your folder structure
it could be the problem.

Getting all of it to work: War, OSGI, Spring Beans, Maven

Trying to deploy a war with a bean file in a Fuse Servicemix (version 4.3.1). I'm using maven to build my war. I can't seem to get this to work. Can anyone provide a website that can tell me how to do this?
This website tells me what to put in the web.xml file but doesn't explain the rest.
http://fusesource.com/docs/esbent/7.0/esb_deploy_osgi/BuildWar-Spring.html.
I've tried several solutions and methods over the course of 19 days. Everyone seems to skin this cat differently but none of them work for me.
fat war (SOLVED):
See answer below
skinny war:
Seems impossible in osgi. Need to manually import too many packages.
This link appears to solve it but seems there a lot of nasty side effects.
http://davidvaleri.wordpress.com/2011/08/17/deploying-spring-mvc-based-web-applications-to-osgi-using-apache-servicemix/
You need to add the Spring OSGi ContextLoaderListener to your web.xml otherwise it doesn't work. You'll also need dependencies to Spring-DM 1.2.1.
Take a look at Pax Web Spring sample and especially the web.xml in it. It's a working example on how to use Spring in Karaf / Fuse-ServiceMix ...
I guess I pointed you to the wrong sample. You need t use the following.
contextClass
org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext
Fat War solution
This is the minimum viable solution that worked for me. I played around trying to remove things and it broke as soon as I did, often without even posting an error message.
directory structure:
src/main/java/test/Test.java
src/main/webapp/WEB-INF/web.xml
src/main/webapp/WEB-INF/applicationContext.xml
pom.xml
...
<groupId>test</groupId>
<artifactId>war-bean-test</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-web</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>jar</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
<supportedProjectType>war</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<!-- IMPORTANT resolution:=optional fixes bug where bundle fails to load unnecessary packages such as bsh. You also need javax.servlet. In Servicemix 4.3.1 it is provided by geronimo servlet. -->
<Import-Package>
javax.servlet
*; resolution:=optional
</Import-Package>
<Export-Package></Export-Package>
<!-- IMPORTANT explicitly adding the jars fixes the numerous CassNotFoundExceptions -->
<Bundle-ClassPath>
.,WEB-INF/classes,{maven-dependencies}
</Bundle-ClassPath>
<Web-ContextPath>warbeantest</Web-ContextPath>
<Webapp-Context>warbeantest</Webapp-Context>
<!-- adding inline=true to Embed-Dependency causes {maven-dependencies} to not work and you will have to add every jar by hand -->
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Directory>WEB-INF/lib</Embed-Directory>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee">
<display-name>war-bean-test</display-name>
<description>war-bean-test</description>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- If you remove this then the spring beans will still work, but you wont be able to fetch services and resources from other osgi bundles -->
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
applicationContext.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-3.0.xsd">
<bean id="test" class="test.Test">
<property name="value" value="1" />
</bean>
</beans>
Test.java
package test;
public class Test {
private int value = 0;
public TestImpl() { }
public void setValue(int value) {
// Should print to console when you load into Fuse Servicemix
System.out.println("testing...");
this.value = value;
}
public int getValue() { return value; }
}

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.

Running a Spring MVC application with Jetty gives "class path resource does not exist"

I'm new to Spring and I encountered a small problem: the web application runs perfectly when using Tomcat but has problem when running it with Jetty.
I run the following commands:
mvn package
java -jar target/dependency/jetty-runner.jar target/*.war
The error I get is:
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring-config.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring-config.xml] cannot be opened because it does not exist
Part of 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
...
</dependencies>
<repositories>
...
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-runner</artifactId>
<version>7.4.5.v20110725</version>
<destFileName>jetty-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Part of my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
...
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
...
</web-app>
Part of my /WEB-INF/applicationContext.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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
...
<import resource="classpath:spring-config.xml" />
</beans>
The relevant directories structure:
- src
--main
---java
----spring-config.xml
---webapp
----WEB-INF
-----applicationContext.xml
-----web.xml
-pom.xml
Seems to be a problem with the classpath definition but I don't know how to solve the problem. I already tried to specify the classpath with java -cp "..." ... or java -Djetty.class.path="..." ...
Any help is very appreciated!
Thank you.
spring-config.xml file should be in src/main/resources. XML files in the Java source directory won't be included on the classpath.
This is automatic if you use the jetty plugin and run with mvn jetty:run (or jetty:run-war).
Your CLASSPATH doesn't include the Spring context.
I'd advise you to package your app into a WAR and deploy that to Jetty. WEB-INF/classes is always in the CLASSPATH, so if you copy your Spring context XML to that directory the class loader will find them.
Do you need a ContextLoaderListener in your web.xml?
I see applicationContext.xml mentioned in your web.xml, but not spring-config.xml. That's the one the class loader is complaining about.

Resources