As soon as I moved the test application to a productive (?) Application and started testing on Tomcat, my REST services based on Spring 3.1 stopped working. Although the index.jsp index is displayed by default, my application (http: // myhost: myport / test-webapp / myrestservice) is not available and I get the Requested resource (/ test-webapp / myrestservice) is not available.
Here is what I did:
Controller:
package com.test.webapp.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.test.webap.entity.Account;
@Controller
@RequestMapping("/myrestservice")
public class AccountController{
@RequestMapping(method = RequestMethod.GET, produces="application/json")
@ResponseBody
public Account getEntity() {
return new Account(
}
}
Servlet Manager Configuration:
package com.test.webapp.web;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import com.test.webapp.config.AppConfig;
public class AppInit implements WebApplicationInitializer {
private static final String DISPATCHER_SERVLET_NAME = "dispatcher";
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(AppConfig.class);
container.addListener(new ContextLoaderListener(dispatcherContext));
ServletRegistration.Dynamic dispatcher = container.addServlet(
DISPATCHER_SERVLET_NAME, new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
Configuration Class:
package com.test.webapp.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan( basePackages = {"com.test.webapp.controller"})
public class AppConfig{
}
And there is not much in 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>Test Web App</display-name>
</web-app>
There is nothing special about my project. Am I missing something? An old project that was a bit like registering incoming JSON requests, etc. (Which has now gone), it works, but I no longer have it :( So, a lot of New Year's blues. Please help me here. Thank you very much!
.