SpringBoot app - server context Path

断了今生、忘了曾经 提交于 2021-02-07 19:06:41

问题


I've generated a Spring Boot web application using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file.

Technologies used:

Spring Boot 2.0.0.M6 , Java 8, maven

Here my security config

   @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();
    }

in my application.properties

server.contextPath=/iberiaWebUtils
server.port=1234

But when I run the app at http://localhost:1234/iberiaWebUtils, instead of going to http://localhost:1234/iberiaWebUtils/login, the app. redirects to http://localhost:1234/login

I also tried with

server.context-path=/iberiaWebUtils

with the same result


回答1:


Starting from Spring Boot 2.0.0 M1 servlet-specific server properties were moved to server.servlet:

Spring Boot 2.0.0 M1 Release Notes

Therefore, you should use the server.servlet.context-path property.




回答2:


Try adding .loginProcessingUrl("/iberiaWebUtils/login") after loginPage("/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();


来源:https://stackoverflow.com/questions/47432524/springboot-app-server-context-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!