spring-mvc - 为什么在入口点 url 中添加项目名称时得到 404
问题描述
如果使用Spring security运行项目,入口点 URL 是:
http://localhost:8099/登录
同时我需要将全局项目名称放在入口点 URL 中,如下所示:
http://localhost:8099/pojoname/login
下面是我的 Spring Security 配置文件:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
.antMatchers("/login").permitAll()
.antMatchers("/register", "/registration", "/editProfile").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login").permitAll()
.usernameParameter("email")
.and()
.logout()
.permitAll();
}
解决方案
请求的特性就是所谓的 web 上下文(或以前的Servlet容器工作中的Servlet上下文)。
这在Spring Boot中得到了开箱即用的支持,并且可以使用server.servlet.contextPath
具有所需值的配置属性进行切换/激活。
在您的application.properties
文件中,添加以下行:
对于版本 < Spring Boot 2.0:
server.contextPath=/pojoname
对于版本 > Spring Boot 2.0:
server.servlet.contextPath=/pojoname
推荐阅读
- mysql - Illuminate \ Database \ QueryException (HY000) SQLSTATE[HY000]:一般错误:1364 字段“verifyToten”没有默认值
- facebook - ionic3:错误:未捕获(承诺):错误:没有 Facebook 提供者
- python - Heroku 部署 - 2 个 github 项目
- python - 使用 for 循环迭代并引用 lst[i] 时的 TypeError/IndexError
- serverless-framework - 如何使用 excludeDevDependencies?
- java - 用 java 解析 {“item”=“value”}
- c# - How to run same test class parallel in c#
- java - Java中的并发编程。试图模拟一组收银台
- php - Laravel:登录后如何正确重定向到多重身份验证
- java - ORA-00900: invalid SQL statement - NamedParameterJdbcTemplate