SpringBoot应用程序 - 服务器上下文路径

en *_*pes 3 spring spring-mvc spring-security spring-boot

我使用Spring Initializer,嵌入式Tomcat,Thymeleaf模板引擎和包作为可执行JAR文件生成了一个Spring Boot Web应用程序.

使用的技术:

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();
    }
Run Code Online (Sandbox Code Playgroud)

在我的 application.properties

server.contextPath=/iberiaWebUtils
server.port=1234
Run Code Online (Sandbox Code Playgroud)

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

我也尝试过

server.context-path=/iberiaWebUtils
Run Code Online (Sandbox Code Playgroud)

结果相同

And*_*lko 11

Spring Boot 2.0.0开始,M1 servlet特定的服务器属性被移动到server.servlet:

在此输入图像描述 Spring Boot 2.0.0 M1发行说明

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