为什么在入口点添加项目名称时得到 404 url

Why got 404 while add project name in entry point url

如果 运行 项目具有 Spring 安全性,入口点 URL 是:

http://localhost:8099/login

同时我需要将全局项目名称放在入口点 URL 中,如下所示:

http://localhost:8099/pojoname/login

下面是我的 Spring 安全配置文件:

@Override
protected void configure(HttpSecurity http) throws Exception {
      http
        .csrf().disable()
        .authorizeRequests()
        .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
        .antMatchers("/login").permitAll()
        .antMatchers("/register", "/registration", "/editProfile").permitAll()
        .anyRequest().authenticated()
        .and()
        .formLogin()
            .loginPage("/login").permitAll()
            .usernameParameter("email")
        .and()
        .logout()
            .permitAll();
}

请求的功能是所谓的 Web 上下文(或以前 Servlet 容器工作中的 Servlet 上下文)。

这在 Spring Boot 中开箱即用,可以使用配置 属性 server.servlet.contextPath 切换/激活期望值。

在您的 application.properties 文件中,添加以下行:

  • 版本<Spring Boot 2.0:

      server.contextPath=/pojoname
    
  • 版本 > Spring Boot 2.0:

      server.servlet.contextPath=/pojoname