简体   繁体   中英

How remove context path in java application

I want to remove context path from my url. when i run project its run in http:///localhost:8080/myApp/ . i want to remove myApp from it. all my config based on java. i change context.xml to this <Context antiJARLocking="true" path="/"/> but when i want to login that based on spring security not working. I also add web.xml based java config like this.

     public class AppInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws   ServletException {
    WebApplicationContext context = getContext();
    servletContext.addListener(new ContextLoaderListener(context));
    ServletRegistration.Dynamic dispatcher =   servletContext.addServlet("DispatcherServlet", new   DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
  }

private AnnotationConfigWebApplicationContext getContext() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation("mypac.config");
    return context;
 }
}

For tomcat server, you can delete your existing ROOT/ directory. Rename your war as ROOT.war and deploy it.

Configure the context root in tomcat's conf/server.xml to use your war file (assuming my_war is your war name)

< Context path="" docBase="my_war" reloadable="true">

you can follow the link also that already answered.

:

  1. Right click your project, choose Properties -> Web Project Settings -> in Context root, change yourApp to / and click OK .
  2. In Servers Explorer , remove yourApp from Tomcat Server .
  3. If you use Maven , right click your project -> choose Maven -> choose Update Project . 如果您使用Maven ,请右键单击您的项目 - >选择Maven - >选择Update Project
  4. Rerun your project.

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