You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot运行遇类加载器错误与权限拒绝,求助实现SharePoint列表展示

Spring Boot 两类错误排查方案

一、类加载器模块冲突错误

错误信息:java.lang.String is in module java.base of loader 'bootstrap'; org.springframework.security.oauth2.jwt.Jwt is in unnamed module of loader 'app'

排查与解决步骤

  • 依赖版本不兼容:Spring Security OAuth2组件与Spring Boot版本不匹配,引发模块加载冲突。
    检查项目依赖配置文件(pom.xml/build.gradle),确保Spring Security OAuth2相关依赖(如spring-security-oauth2-jose、spring-security-oauth2-resource-server)版本与Spring Boot父版本一致,优先通过Spring Boot依赖管理统一版本。
  • 依赖Scope配置错误:若相关依赖被设置为provided或test,会导致运行时类加载器无法找到对应类,触发跨模块加载异常。
    调整依赖的scope属性,生产环境所需依赖保持默认的compile(Maven)或implementation(Gradle)。
  • JDK模块系统未正确声明依赖:使用JDK9+模块系统时,module-info.java未声明对Spring Security OAuth2模块的依赖。
    在module-info.java中添加声明:requires org.springframework.security.oauth2.jwt;。

二、AccessDeniedException权限拒绝错误

错误栈信息:

org.springframework.security.access.AccessDeniedException: Access is denied
at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:73) ~[spring-security-core-5.7.5.jar:5.7.5]

排查与解决步骤

  • Spring Security未放行目标接口:
    检查Security配置类(继承WebSecurityConfigurerAdapter或使用SecurityFilterChain),确保/leave接口被加入放行列表,示例配置:
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests(auth -> auth
                .requestMatchers("/leave").permitAll()
                .anyRequest().authenticated()
        );
        return http.build();
    }
    
  • 方法级权限注解配置缺失或错误:
    若项目启用了方法级权限控制(如@EnableGlobalMethodSecurity),需在leave()方法上添加对应权限注解,比如@PreAuthorize("permitAll()")。
  • SharePoint客户端权限不足:
    检查getSharepointClient()初始化的客户端是否拥有目标SharePoint站点、列表的访问权限,确认客户端的token、账号密码或应用权限配置正确,可单独测试SharePoint API调用是否正常。
  • Repository层权限控制限制:
    若项目对Repository层做了权限管控,需检查LeaveRequestDetailRepo的方法是否配置了正确的权限规则。

内容的提问来源于stack exchange,提问作者v k

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 20:05:30