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

Scala/Pac4j/Play框架新手遇类型不匹配编译错误,寻求排查修复方案

Hey Priyanka, let's break down what's going on here and walk through how to fix it!

问题原因分析

The core issue here is almost certainly a dependency version mismatch between your original Activator setup and the sbt run command you're using now. Here's why:

  • Activator is just a wrapper around sbt, but it often pins specific versions of sbt, Play, and related libraries (like pac4j) to ensure compatibility. When you switched to raw sbt run, you might be using a different sbt version that pulls in incompatible versions of pac4j or Play.
  • The type mismatch error (AuthenticatedRequest vs List[CommonProfile]) is a dead giveaway: pac4j's Play integration changed how it exposes user profiles across versions. Older versions might have passed the profile list directly to your action handlers, while newer versions wrap profiles in an AuthenticatedRequest object. Since your code was working with Activator, it's tuned to the old dependency set, but sbt run is pulling in a newer (or older) incompatible version.
修复方案

Let's tackle this step by step:

  1. Lock your sbt version to match Activator's
    Activator uses a specific sbt version under the hood. To replicate that, create or update the project/build.properties file in your project with the exact sbt version your original Activator setup used. For example:

    sbt.version=1.5.5
    

    (If you don't remember the version, check the original workspace's project/build.properties or look up the Activator version you used—each Activator release maps to a specific sbt version.)

  2. Pin compatible pac4j-play and Play versions
    pac4j and Play have strict version compatibility rules. Make sure your build.sbt explicitly specifies versions that work together. For example:

    • If you're using Play 2.8.x, use pac4j-play 11.x:
      libraryDependencies += "org.pac4j" %% "pac4j-play" % "11.0.0"
      
    • For Play 2.7.x, use pac4j-play 10.x:
      libraryDependencies += "org.pac4j" %% "pac4j-play" % "10.0.0"
      

    Double-check the pac4j version compatibility matrix to match your original working setup.

  3. Clean and refresh dependencies
    Old cached dependencies might be causing conflicts. Run these commands in your project root to start fresh:

    sbt clean
    sbt reload
    sbt update
    

    This will clear old build artifacts, reload your sbt configuration, and download the exact versions you specified.

  4. Verify your action code (if needed)
    If after fixing dependencies you still see issues, double-check how you're handling authenticated requests. For newer pac4j-play versions, you'll access profiles from the request object instead of a direct list:

    // Example of correct usage for newer pac4j versions
    def protectedAction = Secure("your-client-name") {
      Action { request: AuthenticatedRequest[AnyContent] =>
        val profile = request.userProfile[CommonProfile]
        Ok(s"Hello, ${profile.getDisplayName}!")
      }
    }
    

    Since your code worked with Activator, this step might not be necessary—but it's a good check if dependency fixes alone don't resolve the error.

内容的提问来源于stack exchange,提问作者priyanka goel

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 10:12:43