【问题标题】:404 error on logout with WAR exploded to Tomcat404 错误注销与 WAR 爆炸到 Tomcat
【发布时间】:2022-11-19 16:30:16
【问题描述】:

当我使用嵌入式 Tomcat(与 IntelliJ)时,我的应用程序工作正常,但是当我在 Tomcat 8 上部署 WAR 文件时,我的一个 URL 响应为 404(我可以登录我的应用程序,但注销时 URL 响应为 404)。当我将 IntelliJ 与 Tomcat 一起使用时,不会发生此问题。

我的 POM 文件:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.2</version>
    <relativePath/> <
</parent>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

配置文件:

protected void configure(HttpSecurity http) throws Exception {

    http
        .csrf().disable();
    http
        .headers()
            .frameOptions().disable();

    http
        .authorizeRequests()
            .anyRequest().permitAll();
}

更新

我换成Tomcat 9 还是有问题。

更新_2

我有 JSF 视图

【问题讨论】:

  • 404 是未找到页面 - 那么返回错误的 URL 是未找到的吗?也许共享有问题的 URL 将有助于获得答案。
  • myApp_war_exploded/注销返回 404
  • context root是在war name之后创建的,war是不是叫myApp_war_exploded.war?我记得区分大小写。
  • 我认为名称的“分解”部分是特定于 IntelliJ 的?正如@LMC 所说,tomcat 只会将 WAR 解压缩到它自己的名称中,并且其中可能不包含“exploded”。所以我怀疑您在应用程序配置中的某处定义了对注销页面的引用为myApp_war_exploded/logout?我认为它应该只是一个相对链接(不包括应用程序名称)或尝试从应用程序上下文本身派生应用程序名称,因为应用程序名称(以及部署的 URL)不必与应用程序 WAR 名称相同.
  • 我试试这个:http.logout().logoutUrl("/myApp_war_exploded/logout").logoutSuccessUrl("/"); 试试这个:http.logout().logoutUrl("/myApp_war_exploded/logout").logoutSuccessUrl("/myApp_war_exploded"); 没有帮助

标签: java spring-boot tomcat spring-security


【解决方案1】:

我发现 tomcat 在没有页面的情况下存在 api 问题,然后我创建了一个按钮并调用了该方法:

 public void logout(){
    userAuthService.logout();
    FacesContext.getCurrentInstance().getExternalContext()
         .invalidateSession();
    FacesContext.getCurrentInstance().getExternalContext()
         .redirect("login.xhtml?faces-redirect=true");
}

【讨论】:

    猜你喜欢
    • 2023-03-07
    • 2017-07-07
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    相关资源
    最近更新 更多