Running afBedSheet sample produces "Service does not exist for Type 'afIocConfig::FactoryDefaults'" error

StackOverflow https://stackoverflow.com/questions/19736876

Question

I'm trying to create a new web application in Fantom programming language using the afBedSheet framework but can't get the simplest example to run.

The code is:

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!")
  }
}

And my build.fan looks like this:

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/`]
    }
}

When I run the command...

fan afBedSheet mt::AppModule 12345

...this is the error I get:

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)

What am I missing here?

Was it helpful?

Solution

Ah, it seems the IocConfig module is not being added as a transitive dependency, hence Service does not exist for Type 'afIocConfig::FactoryDefaults'.

The quickest fix is to add the following to your build.fan:

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

That is, add afIocConfig as a dependency and define your AppModule as pod meta. Then start BedSheet with just the pod name:

fan afBedSheet mt 12345

This is an issue with v1.0.16 when afIocConfig was split out into it's own pod - the tests passed because afBedSheet itself depends on afIocConfig. d'Oh!

This should be fixed in afBedSheet v1.1.0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top