简体   繁体   中英

Java web app only working in Netbeans

I am working on a Spring web app and everything works perfectly when i run it from netbeans. My project is completely annotation based, the context.xml file is empty and there are no other XML files to speak of. The war file resulting from the build process deploys fine under the tomcat manager webpage and i'm able to access the login page. As soon as the login button is pressed, what would normally be a redirection to the home page is not happening. One thing I am noticing is that when i click on my app in tomcat manager i am brought to localhost:8080/MDHIS_WebClient which correctly displays the login page. As soon as i hit login, it gives me a 404 error with URL localhost:8080/login which is the name of the post method in my main controller that does the login process (notice the webapp name not in the URL anymore). No matter what i manually enter in the URL bar, known valid URLs, i never get an actual page and it looks like the login process is not even happening. I have looked at all the Tomcat logs and there are no errors logged whatsoever. I did read other posts but i dind't find a similar set of symptoms. I am completely baffled by this one and I don't even see what relevant code i could post here.

If you have ever encountered this issue please help.

Regards

* EDIT *

This is my onStartup() method in my ApplicationInitializer class :

@Override
public void onStartup(ServletContext container) throws ServletException 
{
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(ApplicationConfiguration.class);
    ctx.setServletContext(container);
    ContextLoaderListener contextLoaderListener = new ContextLoaderListener(ctx);
    ctx.getServletContext().addListener(contextLoaderListener);
    ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));
    servlet.setLoadOnStartup(1);
    servlet.addMapping("/");
}

Finally found the answer in a post on another forum :

In your tomcat's conf/server.xml add:

<Context path="" docBase="NameOfYourWar" debug="0" reloadable="true"></Context>

in your server.xml file before ending tag

This will ensure your context being loaded without the war file name in the root. Alternative is rename your war file to ROOT.war and delete the ROOT folder in webapps, and deploy your own ROOT.war file.

I can confirm this works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM