gpt4 book ai didi

java - 如果尝试在 RestHelper 类中使用相同路径添加 JsonPut 和 JsonPost 方法,则无法编译代码

转载 作者:行者123 更新时间:2023-12-02 00:22:04 24 4
gpt4 key购买 nike

我正在尝试在 RestHelper 类中添加 JsonPut 和 JsontPost 方法,其路径如下所示:

object MembershipAPI extends RestHelper with LogHelper {
serve {
case JsonPost("api" :: "v1" :: "group_memberships" :: group_id :: user_id :: Nil, request) =>
() => Full(GroupMembershipController.Join(group_id, user_id, request))
case JsonPut("api" :: "v1" :: "group_memberships" :: group_id :: user_id :: Nil, request) =>
() => Full(GroupMembershipController.Join(group_id, user_id, request))
case JsonDelete("api" :: "v1" :: "group_memberships" :: group_id :: user_id :: Nil, request) =>
() => Full(GroupMembershipController.Leave(group_id, user_id, request))
}
}

当运行 sbt 编译时,我收到此错误:

java.lang.Error: ch.epfl.lamp.fjbg.JCode$OffsetTooBigException: offset too big to fit in 16 bits: 51511
at ch.epfl.lamp.fjbg.JFieldOrMethod.writeTo(JFieldOrMethod.java:130)
at ch.epfl.lamp.fjbg.JClass.writeTo(JClass.java:358)
at scala.tools.nsc.backend.jvm.BytecodeWriters$ClassBytecodeWriter$class.writeClass(BytecodeWriters.scala:87)
at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anon$2.writeClass(GenJVM.scala:82)
at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.emitClass(GenJVM.scala:172)
at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genClass(GenJVM.scala:304)
at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJVM.scala:86)
at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJVM.scala:86)
at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(HashMap.scala:102)
at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(HashMap.scala:102)
at scala.collection.Iterator$class.foreach(Iterator.scala:652)
at scala.collection.mutable.HashTable$$anon$1.foreach(HashTable.scala:157)
at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala:190)
at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:43)
at scala.collection.mutable.HashMap$$anon$2.foreach(HashMap.scala:102)
at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase.run(GenJVM.scala:86)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:949)
at scala.tools.nsc.Global$Run.compile(Global.scala:1034)
at xsbt.CompilerInterface.run(CompilerInterface.scala:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at xsbt.AnalyzingCompiler.call(AnalyzingCompiler.scala:40)
at xsbt.AnalyzingCompiler.apply(AnalyzingCompiler.scala:18)
at sbt.Compile.processScala(Compile.scala:76)
at sbt.CompilerCore$$anonfun$1.apply(Compile.scala:27)
at sbt.CompilerCore$$anonfun$1.apply(Compile.scala:27)
at sbt.CompilerCore$$anonfun$process$1$1.apply(Compile.scala:22)
at sbt.CompilerCore$$anonfun$process$1$1.apply(Compile.scala:22)
at sbt.CompilerCore$$anonfun$doCompile$3.apply(Compile.scala:45)
at sbt.CompilerCore$$anonfun$doCompile$3.apply(Compile.scala:42)
at scala.Option.orElse(Option.scala:102)
at sbt.CompilerCore.doCompile(Compile.scala:41)
at sbt.CompilerCore.apply(Compile.scala:29)
at sbt.AbstractCompileConditional.run$1(Conditional.scala:341)
at sbt.AbstractCompileConditional$$anonfun$3.apply(Conditional.scala:344)
at sbt.AbstractCompileConditional$$anonfun$3.apply(Conditional.scala:344)
at sbt.classfile.Analyze$.apply(Analyze.scala:110)
at sbt.AbstractCompileConditional.execute(Conditional.scala:344)
at sbt.Conditional$class.run(Conditional.scala:43)
at sbt.AbstractCompileConditional.run(Conditional.scala:231)
at sbt.BasicScalaProject.sbt$BasicScalaProject$$doCompile(DefaultProject.scala:260)
at sbt.BasicScalaProject$$anonfun$compileAction$1.apply(DefaultProject.scala:274)
at sbt.BasicScalaProject$$anonfun$compileAction$1.apply(DefaultProject.scala:274)
at sbt.TaskManager$Task.invoke(TaskManager.scala:62)
at sbt.impl.RunTask.doRun$1(RunTask.scala:77)
at sbt.impl.RunTask.runTask(RunTask.scala:85)
at sbt.impl.RunTask.run(RunTask.scala:32)
at sbt.impl.RunTask$.apply(RunTask.scala:17)
at sbt.impl.RunTask$.apply(RunTask.scala:16)
at sbt.Project$class.run(Project.scala:98)
at sbt.Project$class.act(Project.scala:129)
at sbt.BasicScalaProject.act(DefaultProject.scala:21)
at sbt.xMain$$anonfun$8.apply(Main.scala:530)
at sbt.xMain$$anonfun$8.apply(Main.scala:530)
at sbt.xMain.withAction(Main.scala:563)
at sbt.xMain.sbt$xMain$$handleAction(Main.scala:530)
at sbt.xMain.handleCommand(Main.scala:520)
at sbt.xMain.processAction(Main.scala:459)
at sbt.xMain.process$1(Main.scala:257)
at sbt.xMain.processArguments(Main.scala:266)
at sbt.xMain.startProject(Main.scala:107)
at sbt.xMain.run(Main.scala:84)
at sbt.xMain.run0$1(Main.scala:35)
at sbt.xMain.run(Main.scala:42)
at xsbt.boot.Launch$.run(Launch.scala:53)
at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:42)
at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:42)
at xsbt.boot.Launch$.launch(Launch.scala:57)
at xsbt.boot.Launch$.explicit(Launch.scala:42)
at xsbt.boot.Launch$.initialized(Launch.scala:38)
at xsbt.boot.Launch$.parsed(Launch.scala:31)
at xsbt.boot.Launch$.configured(Launch.scala:21)
at xsbt.boot.Launch$.apply(Launch.scala:16)
at xsbt.boot.Launch$.apply(Launch.scala:13)
at xsbt.boot.Boot$.runImpl(Boot.scala:24)
at xsbt.boot.Boot$.run(Boot.scala:19)
at xsbt.boot.Boot$.main(Boot.scala:15)
at xsbt.boot.Boot.main(Boot.scala)
Caused by: ch.epfl.lamp.fjbg.JCode$OffsetTooBigException: offset too big to fit in 16 bits: 51511
at ch.epfl.lamp.fjbg.JCode.checkOffset16(JCode.java:903)
at ch.epfl.lamp.fjbg.JCode.patchAllOffset(JCode.java:982)
at ch.epfl.lamp.fjbg.JCode.freeze(JCode.java:102)
at ch.epfl.lamp.fjbg.JMethod.freeze(JMethod.java:89)
at ch.epfl.lamp.fjbg.JFieldOrMethod.writeTo(JFieldOrMethod.java:127)
... 79 more
Error during sbt execution: java.lang.Error: ch.epfl.lamp.fjbg.JCode$OffsetTooBigException: offset too big to fit in 16 bits: 51511

我不知道为什么会发生这种情况以及如何解决这个问题?

提前谢谢您!

最佳答案

创建的部分函数太大,Scala 编译器无法编译。这是一个issue使用scala编译器。

要解决此问题,您需要将选择器分成多个服务语句。所以只要找到一个有逻辑断点的地方,制作两个RestHelper函数就可以了。

例如,

object MembershipAPIOne extends RestHelper with LogHelper {
serve {
case JsonPost("api" :: "v1" :: "group_memberships" :: group_id :: user_id :: Nil, request) =>
() => Full(GroupMembershipController.Join(group_id, user_id, request))
case JsonPut("api" :: "v1" :: "group_memberships" :: group_id :: user_id :: Nil, request) =>
() => Full(GroupMembershipController.Join(group_id, user_id, request))
}
}

object MembershipAPITwo extends RestHelper with LogHelper {
serve {
case JsonDelete("api" :: "v1" :: "group_memberships" :: group_id :: user_id :: Nil, request) =>
() => Full(GroupMembershipController.Leave(group_id, user_id, request))
}
}

参见http://www.assembla.com/spaces/liftweb/wiki/REST_Web_Services以获得更多帮助。

关于java - 如果尝试在 RestHelper 类中使用相同路径添加 JsonPut 和 JsonPost 方法,则无法编译代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10763291/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com