San*_*non 5 java spring-security contextpath spring-boot tomcat9
在我的Spring Boot(2.0)应用程序中,我在我的application.properties文件中设置了上下文路径,如下所示
server.servlet.context-path=/myApp
Run Code Online (Sandbox Code Playgroud)
另外,我有以下安全配置类扩展 WebSecurityConfigurerAdapter
@Override
protected void configure(HttpSecurity http) throws Exception {
// TODO Auto-generated method stub
http
.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.GET,"/uifiles/dist/css/**").permitAll()
.antMatchers(HttpMethod.GET,"/uifiles/plugins/icheck-bootstrap/**").permitAll()
.antMatchers(HttpMethod.GET,"/uifiles/plugins/fontawesome-free/css/**").permitAll()
.antMatchers(HttpMethod.GET,"/css/**").permitAll()
.antMatchers(HttpMethod.GET, "/uifiles/**").permitAll()
.antMatchers(HttpMethod.GET, "/error/**").permitAll()
.antMatchers(HttpMethod.GET,"/files/**").permitAll()
.antMatchers(HttpMethod.GET,"/files/fonts/**").permitAll()
.antMatchers(HttpMethod.GET,"/files/images/**").permitAll()
.and()
.authorizeRequests().antMatchers("/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.successForwardUrl("/home")
.defaultSuccessUrl("/home")
.permitAll()
.and()
.logout()
.invalidateHttpSession(true)
.clearAuthentication(true)
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login")
.and()
.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint());
}
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序(来自Spring Tool Suit)并通过 url 访问应用程序时
它工作正常并打开登录页面
但是,当我进入
它将我重定向到 http://localhost:8080/login (这给出了一个 404 页面)
我想要 http://localhost:8080/myApp/ & http://localhost:8080/myApp/login 打开登录页面
登录页面位于项目文件夹的根目录中。另外,spring.mvc.view.suffix=.jsp我的 application.properties 中有。因此控制器会自动为请求添加文件扩展名。
注销功能工作正常,它重定向到 http://localhost:8080/myApp/login
| 归档时间: |
|
| 查看次数: |
589 次 |
| 最近记录: |