类型 org.springframework.security.core.GrantedAuthority 没有可用的源代码

问题描述 投票:0回答:1
  • 我有一个遗留的多模块 GWT 项目。
  • 其中一个模块包含 DTO 和 Enum 类。
  • 其中一个 DTO 类扩展了
    org.springframework.security.core.GrantedAuthority
    类,因此在 pom.xml 中它具有 org.springframework.security. 的 Maven spring-security-core
  • 依赖项
  • 当我尝试运行
    package
    命令时,我收到消息:

类型没有源代码 org.springframework.security.core.GrantedAuthority;你忘了吗 继承一个必需的模块?

  • 我尝试应用在一些帖子中推荐的解决方案,这些帖子我发现有类似的消息,我什至发现 一个与相同的错误相关,但这些解决方案都不适合我。

您能帮我找出导致此错误的原因以及我该如何解决吗?


要重现问题,您可以按照我所做的步骤操作:

  1. 我使用 GWT Archetypes 创建了一个名为

    GWTRPCModular
    的基本项目;和:

    • JDK 17(但我也尝试过 8)
    • 日食 2023-03
    • Apache Maven 3.8.6
    • GWT 2.10.0
  2. 该项目由 3 个模块生成:

    GWTRPCModular-client
    GWTRPCModular-server
    GWTRPCModular-shared

  3. 我为 DTO 添加了一个名为

    GWTRPCModular-model
    的模块 (类似于我的遗留项目) 并在 pom.xml 中添加了必要的依赖项。

  4. 我将

    <source path="model" />
    包含在 *.gwt.xml 文件中。

  5. 我创建了

    UserSessionDTO
    班级

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

public class UserSessionDTO extends User {

    private static final long serialVersionUID = -6391317902265663080L;

    public UserSessionDTO(String username, String password, Collection<? extends GrantedAuthority> authorities) {
        super(username, password, authorities);
        // TODO Auto-generated constructor stub
    }
}
  1. 我运行了
    mvn clean install
  2. 最后我运行了
    mvn package
    ,消息出现了:
...
[INFO] --- gwt-maven-plugin:1.0.1:compile (default-compile) GWTRPCModular-client ---
[INFO] Compiling module com.foo.gwtmodular.App
[INFO]    Tracing compile failure path for type 'com.foo.gwtmodular.model.dto.UserSessionDTO'
[INFO]       [ERROR] Errors in 'com/foo/gwtmodular/model/dto/UserSessionDTO.java'
[INFO]          [ERROR] Line 8: No source code is available for type org.springframework.security.core.userdetails.User; did you forget to inherit a required module?
[INFO]          [ERROR] Line 12: No source code is available for type org.springframework.security.core.GrantedAuthority; did you forget to inherit a required module?
...  

如果您需要其他任何内容来审查此案例,请告诉我。

提前感谢您提供的任何帮助!

java maven spring-security gwt gwt-rpc
1个回答
0
投票

在您的 GWT (*.gwt.xml) 模块文件中,您还需要一个

<inherits>
标签用于此 spring 依赖项。

虽然这个 spring 库可能没有自己的 GWT 模块文件,所以你需要创建自己的。在您的客户端项目中,您可以创建一个包,例如

org.springframework.security
,为 spring 库创建一个 GWT 模块文件并将其放入包中。然后你可以在你的主 GWT 模块文件中继承它

参考这个问题/答案: https://stackoverflow.com/a/70538165/1920835

© www.soinside.com 2019 - 2024. All rights reserved.