Thursday, December 5, 2013

Tapestry 5 Invalid configuration

I met following configuration exception in logs:
Caused by: java.lang.IllegalArgumentException: Service 'ChangeLogProcessor' is configured using 
org.apache.tapestry5.ioc.OrderedConfiguration, not org.apache.tapestry5.ioc.Configuration.
 at org.apache.tapestry5.ioc.internal.util.WrongConfigurationTypeGuard.findResource(WrongConfigurationTypeGuard.java:40)
 at org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources.findResource(DelegatingInjectionResources.java:36)
 at org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources.findResource(DelegatingInjectionResources.java:38)

Problem was related to Tapestry 5 chain of commands builder. It's Tapestry 5 build-in service that helps to implement that design pattern. My chain of commands definition was:
public static ChangeLogProcessor buildChangeLogProcessor(List<ChangeLogProcessor> commands,
    @InjectService("ChainBuilder") ChainBuilder chainBuilder) {
    return chainBuilder.build(ChangeLogProcessor.class, commands);
}

public static void contributeChangeLogProcessor(
    final Configuration<ChangeLogProcessor> configuration,
    final @Autobuild ChangeLogBoxProcessor changeLogBoxProcessor) {
    configuration.add(changeLogBoxProcessor);
}
After some time I found that problem was in contribute method, in build method is configuration defined as List which should be in contribute method defined as OrderedConfiguration not as Configuration. So following corrected code works fine:
public static void contributeChangeLogProcessor(
    final OrderedConfiguration<ChangeLogProcessor> configuration,
    final @Autobuild ChangeLogBoxProcessor changeLogBoxProcessor) {
    configuration.add("boxProcessor", changeLogBoxProcessor);
}

No comments:

Post a Comment