Skip to content

Instantly share code, notes, and snippets.

@danbev
Created September 12, 2012 12:57
Show Gist options
  • Save danbev/3706418 to your computer and use it in GitHub Desktop.
Save danbev/3706418 to your computer and use it in GitHub Desktop.
Multiple Routes in a single deployment

What happens if you declare multiple implementations of AbstractRoutingModule?

You get the following deployment error:

13:41:36,425 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC00001: Failed to start service jboss.deployment.unit."aerogear-controller-demo.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."aerogear-controller-demo.war".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type [RoutingModule] with qualifiers [@Default] at injection point [[parameter 1] of [constructor] @Inject public org.jboss.aerogear.controller.router.DefaultRouter(RoutingModule, BeanManager, ViewResolver, ControllerFactory, SecurityProvider)]. Possible dependencies [[Managed Bean [class org.jboss.aerogear.controller.demo.Routes2] with qualifiers [@Any @Default], Managed Bean [class org.jboss.aerogear.controller.demo.Routes] with qualifiers [@Any @Default]]]
	at org.jboss.as.weld.services.WeldService.start(WeldService.java:83)
	at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
	at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [classes.jar:1.6.0_33]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [classes.jar:1.6.0_33]
	at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_33]
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type [RoutingModule] with qualifiers [@Default] at injection point [[parameter 1] of [constructor] @Inject public org.jboss.aerogear.controller.router.DefaultRouter(RoutingModule, BeanManager, ViewResolver, ControllerFactory, SecurityProvider)]. Possible dependencies [[Managed Bean [class org.jboss.aerogear.controller.demo.Routes2] with qualifiers [@Any @Default], Managed Bean [class org.jboss.aerogear.controller.demo.Routes] with qualifiers [@Any @Default]]]
	at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:278)
	at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:244)
	at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:107)
	at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:127)
	at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:346)
	at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:331)
	at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366)
	at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:83)
	at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
	... 5 more

From inspecting the stacktrace above we can determine that WELD, the CDI implementation in use, cannot determine what to inject. What you have to do is provide a way to identify, or qualify, the type you want to have inject. This is done by providing a qualifier:

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.inject.Qualifier;

@Documented
@Retention (RetentionPolicy.RUNTIME)
@Qualifier
public @interface ProdType {
}

And then specifying this qualifier on the Routes class you want to use:

@ProdType
public class Routes2 extends AbstractRoutingModule {
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment