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

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

我使用 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 Boot 2.0.0 M1 servlet 特定的服务器属性开始移至 server.servlet :

enter image description here
Spring Boot 2.0.0 M1 Release Notes

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

关于SpringBoot 应用程序 - 服务器上下文路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47432524/

相关文章:

java - 为 Spring Boot 实现字节服务

spring - Zuul 无法将流量路由到 Kubernetes 上的服务

Spring 阅读请求正文两次

javascript - $resource.save 使用 "Resource"而不是简单的 ID 进行响应

java - 如何设置 RestTemplate 以重试对某些响应状态代码的调用?

spring-boot - 通过 docker 容器拒绝访问本地数据库

java - 在 Tomcat 中访问 externalize application.properties for Spring boot 应用程序?

java - Spring Boot——嵌入式Tomcat

java - 为什么xsi :schemaLocation declaration?中有冗余

java - 有没有办法禁止将类用作 spring bean?