我使用 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
:
Spring Boot 2.0.0 M1 Release Notes
因此,您应该使用 server.servlet.context-path
属性。
关于SpringBoot 应用程序 - 服务器上下文路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47432524/