当前位置: 首页 > 知识库问答 >
问题:

在Spring Boot应用程序中访问上下文路径(根文件夹)不显示登录页面

丁阳羽
2023-03-14

在我的Spring Boot(2.0)应用程序中,我在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());  

    }

它工作正常,打开登录页面

但是,当我进去的时候

http://localhost:8080/myapp/

  • Spring Boot 2.1.7
  • Tomcat 9.0.21
  • JDK 1.8

共有1个答案

百里光熙
2023-03-14

您是否尝试将:.loginpage(“/login”)更改为.loginpage(“/login.html”)

 类似资料:
  • 我已经使用Spring初始值设定项、嵌入式Tomcat、Thymeleaf模板引擎和作为可执行JAR文件的包生成了一个Spring Boot web应用程序。 使用的技术: Spring启动2.0.0。M6,Java8, Maven 这是我的安全配置 在我的 但当我在http://localhost:1234/iberiaWebUtils,而不是去http://localhost:1234/ibe

  • 问题内容: 我试图在我的Java独立代码中使用来加载位于我的类路径中的jar文件内部的。 applicationContext.xml条目如下, 而且,当我尝试以这种方式加载bean时,我得到了。不能通过这种方式加载bean吗? jar文件作为maven依赖项添加到我的类路径中。当我在该项目的Eclipse中看到Java Build Path时,看到该jar链接为M2_REPO /…/.。 我以为

  • 我正在从主类访问资源文件夹中的文件 我收到了这个错误: 我甚至打开了jar文件,remoteUnitsIdsInOldServer.txt文件就在那里,在类内部

  • 编写一个简单的spring程序从filepathxmlapplication上下文中读取bean,但得到以下异常。 但我确信在可以访问xml bean定义文件。

  • 问题内容: 问候 , 有什么方法可以将值从web.xml context-param转换为Spring上下文吗? 例如,我将web.xml中的值定义为: 我想将该值分配给bean属性为: 提前致谢? 问题答案: 是的- 本文介绍了详细信息。简而言之,您需要: 然后使用以下属性: 或搭配

  • 我正在尝试找到一种方法来显式指定部署到Glassfish的Web应用程序的上下文路径3.1.2.2但到目前为止我还没有运气。有人能对此提供指导吗?背景如下: 我有一个Web应用程序,它由两个单独的Netbean(7.0)项目组成。第一个是Web服务,称为FOWS。第二个是使用FOWS网络服务的面向用户的Web应用程序。它被称为FooApp。 我最近将glassfish升级到3.1.2.2,希望解决