KNSter
KNSter

Reputation: 3

Getting 404 after deploying to app server but not locally

I am building web service with Spring @RestController. When testing it locally, everything is fine. However, after deploy the app to a remote application server, I am getting 404 back when hitting the same endpoint. Here's my codes:

@RestController
public class HelloRestController
{   
    @RequestMapping(  value = "/hello", method = RequestMethod.GET )
    public String hello()
    {
        return "hello";
    }
}

Here's my web application initializer. Note: I don't have a web.xml file.

public class MyApplicationInitializer implements WebApplicationInitializer
{
    @Override
    public void onStartup( ServletContext servletContext ) throws ServletException
    {
        AnnotationConfigWebApplicationContext ctx =
            new AnnotationConfigWebApplicationContext();

        servletContext.addListener( new ContextLoaderListener( ctx ) );

        ctx.register( WebApplicationConfig.class, ApplicationConfig.class );

        ctx.setServletContext( servletContext );

        Dynamic dispatcher =
            servletContext.addServlet( "SpringServlet", new DispatcherServlet( ctx ) );

        dispatcher.addMapping( "/" );
        dispatcher.setLoadOnStartup( 1 );
    }
}

When I deploy the app locally to Tomcat-8.0.15 and hit "localhost:8080/myApp/hello", it returns "hello". However, after deploying the app to the remote application server (also Tomcat 8), I am getting 404 back when trying hit the same endpoint.

Thanks in advance for your helps!

Upvotes: 0

Views: 5535

Answers (1)

yunbugg
yunbugg

Reputation: 37

the code does look good. double check if there are any environment related issues that will causes failure to spring's bean initialization--this will cause the dispatcher servlet to fail and hence can result in a 404. common issues could be database connection being refused, classpath conflicts, JVM differences between remote application server and local.

you should be able to locate some tomcat logs to find out if there is any issues in the remote server.

Upvotes: 1

Related Questions