运行afBedSheet示例生成“类型'afIocConfig :: FactoryDe​​faults'的服务不存在”错误

时间:2013-11-01 23:09:40

标签: java runtime-error fantom afbedsheet

我正在尝试使用FantomafBedSheet framework编程语言创建新的Web应用程序,但无法运行最简单的示例。

代码是:

using afBedSheet
using afIoc

class AppModule {
  @Contribute
  static Void contributeRoutes(OrderedConfig conf) {
    conf.add(Route(`/hello/**`, HelloPage#hello))
  }
}

class HelloPage {
  Text hello(Str name, Int iq := 666) {
    return Text.fromPlain("Hello! I'm $name and I have an IQ of $iq!")
  }
}

我的build.fan看起来像这样:

using build

class Build : BuildPod {

    new make() {
        podName    = "mt"
        summary    = "TODO write a description here"
        depends    = ["sys 1.0+", "afBedSheet 1.0.16+", "afIoc 1.4.6+"]
        srcDirs    = [`fan/`, `test/`]
    }
}

当我运行命令时......

fan afBedSheet mt::AppModule 12345

......这是我得到的错误:

C:\dev\mt2\fan>fan afBedSheet mt::AppModule 12345
[08:49:36 02-Nov-13] [info] [afBedSheet] Starting BedSheet WebApp 'mt::AppModule' on port 12345
[08:49:36 02-Nov-13] [info] [web] WispService started on port 12345
[08:49:36 02-Nov-13] [info] [afBedSheet] Found mod 'mt::AppModule'
[08:49:36 02-Nov-13] [info] [afIoc] Adding module definition for mt::AppModule
[08:49:36 02-Nov-13] [info] [afIoc] Adding module definition for afBedSheet::BedSheetModule
afIoc::IocErr: Service does not exist for Type 'afIocConfig::FactoryDefaults' defined in contribution method afBedSheet::BedSheetModule.contributeFactoryDefaults.
Ioc Operation Trace:
  [ 1] Building IoC Registry
  [ 2] Validating contribution definitions
Stack Trace:
        at fan.afIoc.IocErr.make(Errs.fan:15)
        at fan.afIoc.Utils.stackTraceFilter(Utils.fan:63)
        at fan.afIoc.RegistryBuilder.build(RegistryBuilder.fan:112)
        at fan.afBedSheet.BedSheetWebMod.onStart(BedSheetWebMod.fan:119)
        at fan.wisp.WispService.onStart(WispService.fan:72)
        at fan.sys.Service$.start(Service$.java:205)
        at fan.wisp.WispService.start(WispService.fan:21)
        at fan.afBedSheet.Main$startServices$3.doCall(Main.fan:54)
        at fan.afBedSheet.Main$startServices$3.call(Main.fan:54)
        at fan.sys.List.each(List.java:555)
        at fan.afBedSheet.Main.startServices(Main.fan:54)
        at fan.afBedSheet.Main.run(Main.fan:48)
        at fan.util.AbstractMain.main(AbstractMain.fan:370)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at fan.sys.Method.invoke(Method.java:559)
        at fan.sys.Method$MethodFunc.callOn(Method.java:230)
        at fan.sys.Method.callOn(Method.java:139)
        at fanx.tools.Fan.callMain(Fan.java:175)
        at fanx.tools.Fan.executeType(Fan.java:140)
        at fanx.tools.Fan.execute(Fan.java:41)
        at fanx.tools.Fan.run(Fan.java:298)
        at fanx.tools.Fan.main(Fan.java:336)

我在这里缺少什么?

1 个答案:

答案 0 :(得分:2)

啊,似乎IocConfig模块没有被添加为传递依赖,因此Service does not exist for Type 'afIocConfig::FactoryDefaults'

最快的解决方法是将以下内容添加到build.fan

depends = ["sys 1.0+", "afBedSheet 1.0.16+", "afIoc 1.4.6+", "afIocConfig 0+"]
meta    = ["afIoc.module" : "mt::AppModule"]

即,将afIocConfig添加为依赖项,并将AppModule定义为pod元。然后使用只是pod名称

启动BedSheet
fan afBedSheet mt 12345

这是v1.0.16的一个问题,当afIocConfig被分割成它自己的pod时 - 由于afBedSheet本身依赖于afIocConfig,因此传递了测试。 D'哦!

这应该在afBedSheet v1.1.0中修复。