【问题标题】:SpringBoot app - server context PathSpring Boot 应用程序 - 服务器上下文路径
【发布时间】:2018-05-06 01:31:20
【问题描述】:

我使用 Spring Initializer、嵌入式 Tomcat、Thymeleaf 模板引擎生成了一个 Spring Boot Web 应用程序,并将其打包为可执行 JAR 文件。

使用的技术:

Spring Boot 2.0.0.M6,Java 8,maven

这是我的安全配置

   @Override
    protected void configure(HttpSecurity http) throws Exception {

        final List<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
        if (activeProfiles.contains("dev")) {
            http.csrf().disable();
            http.headers().frameOptions().disable();
        }

        http
                .authorizeRequests()
                .antMatchers(publicMatchers()).permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage("/login").defaultSuccessUrl("/iberia/list")
                .failureUrl("/login?error").permitAll()
                .and()
                .logout().permitAll();
    }

在我的application.properties

server.contextPath=/iberiaWebUtils
server.port=1234

但是当我在http://localhost:1234/iberiaWebUtils 运行应用程序时,而不是去http://localhost:1234/iberiaWebUtils/login,应用程序。重定向到http://localhost:1234/login

我也试过

server.context-path=/iberiaWebUtils

结果相同

【问题讨论】:

  • 我无法重现您所面临的问题。我已经用 spring-security 和 thymeleaf 配置了项目。请分享您的详细配置,以便调试跨度>

标签: spring spring-mvc spring-boot spring-security


【解决方案1】:

从 Spring Boot 2.0.0 M1 开始,特定于 servlet 的服务器属性已移至 server.servlet:

Spring Boot 2.0.0 M1 Release Notes

因此,您应该使用server.servlet.context-path 属性。

【讨论】:

    【解决方案2】:

    尝试在loginPage("/login") 之后添加.loginProcessingUrl("/iberiaWebUtils/login")

        http
                .authorizeRequests()
                .antMatchers(publicMatchers()).permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage("/login")    
                .loginProcessingUrl("/iberiaWebUtils/login")
                .defaultSuccessUrl("/iberia/list")
                .failureUrl("/login?error").permitAll()
                .and()
                .logout().permitAll();
    

    【讨论】:

      猜你喜欢
      • 2013-12-22
      • 2011-04-23
      • 1970-01-01
      • 2020-05-07
      • 1970-01-01
      • 2021-08-12
      • 1970-01-01
      • 2017-06-05
      相关资源
      最近更新 更多