Java 访问上下文路径(根文件夹)不会在Spring引导应用程序中显示登录页
在我的springboot(2.0)应用程序中,我在Java 访问上下文路径(根文件夹)不会在Spring引导应用程序中显示登录页,java,spring-boot,spring-security,tomcat9,contextpath,Java,Spring Boot,Spring Security,Tomcat9,Contextpath,在我的springboot(2.0)应用程序中,我在application.properties文件中设置了上下文路径,如下所示 server.servlet.context-path=/myApp 此外,我还有以下安全配置类扩展WebSecurityConfigurerAdapter @Override protected void configure(HttpSecurity http) throws Exception { // TODO Auto-gen
application.properties
文件中设置了上下文路径,如下所示
server.servlet.context-path=/myApp
此外,我还有以下安全配置类扩展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());
}
当我运行应用程序(从Spring Tool Suit)并通过url访问应用程序时
它可以正常工作并打开登录页面
但是,当我进去的时候
它使我转向
(这是404页)
我两者都要
&
打开登录页面
登录页面位于项目文件夹的根目录中。
另外,我的application.properties中有spring.mvc.view.suffix=.jsp
。因此,控制器会自动为请求添加文件扩展名
注销功能正常工作,并重定向到
- 弹簧靴2.1.7
- Tomcat 9.0.21
- JDK 1.8
.loginPage(“/login”)
到
.loginPage(“/login.html”)
这是一次彻底的尝试——我隐约记得这是多年前的一次绝对重定向
尝试使用“${server.servlet.context path}/login”作为loginPage的值
如果有效-很好,如果不行,我会尝试深入研究,看看能找到什么。更新
.authorizeRequests().antMatchers(“/login”).permitAll()
至
.authorizeRequests()
.antMatchers(“/”).permitAll()
.antMatchers(“/login”).permitAll()
并将控制器的@RequestMapping
更新为具有多个路径,如{”/“,“/login”}。
例如:
@Controller
public class ExampleController {
@RequestMapping(value = { "/", "/login" })
public String login() {
return "login";
}
}
你能在类中添加调试点来调试代码吗
org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint
方法名称
buildRedirectUrlToLoginPage
。这将很容易找到问题所在。我在根文件夹中有login.jsp
页面,在application.properties文件中有spring.mvc.view.suffix=.jsp
。因此,当我调用.loginPage(“/login”)
时,它将调用login.jsp。您可以添加控制器代码吗。您是否使用反向代理?@SangeetMenon您可以检查这是否对您有效吗?不幸的是,由于当前的新冠病毒-19情况,我有几天无法检查。一旦情况缓和,我会回来的。不幸的是,由于目前的新冠病毒-19情况,我有几天无法检查。一旦情况缓和,我会回来的。不幸的是,由于目前的新冠病毒-19情况,我有几天无法检查。一旦情况缓和,他就会回来。