简体   繁体   English

如何在java应用程序中删除上下文路径

[英]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/ . 当我在http:///localhost:8080/myApp/运行项目时。 i want to remove myApp from it. 我想从中删除myApp。 all my config based on java. 我所有的配置都基于java。 i change context.xml to this <Context antiJARLocking="true" path="/"/> but when i want to login that based on spring security not working. 我将context.xml更改为此<Context antiJARLocking="true" path="/"/>但是当我想基于spring security登录时无效。 I also add web.xml based java config like this. 我也像这样添加基于web.xml的java配置。

     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. 对于tomcat服务器,您可以删除现有的ROOT /目录。 Rename your war as ROOT.war and deploy it. 将您的战争重命名为ROOT.war并进行部署。

Configure the context root in tomcat's conf/server.xml to use your war file (assuming my_war is your war name) 在tomcat的conf/server.xml配置上下文根以使用war文件(假设my_war是你的战争名称)

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

you can follow the link also that already answered. 您也可以按照已经回答的链接进行操作

If you're using Eclipse ide : 如果您正在使用Eclipse ide

  1. Right click your project, choose Properties -> Web Project Settings -> in Context root, change yourApp to / and click OK . 右键单击您的项目,在Context root中选择Properties - > Web Project Settings - >,将yourApp更改为/ ,然后单击OK
  2. In Servers Explorer , remove yourApp from Tomcat Server . Servers Explorer ,从Tomcat Server删除您的yourApp
  3. (Option) If you use Maven , right click your project -> choose Maven -> choose Update Project . (选项)如果您使用Maven ,请右键单击您的项目 - >选择Maven - >选择Update Project
  4. Rerun your project. 重新运行您的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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