camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakub Kotowski <>
Subject Re: Setting up CamelContext with Guice
Date Fri, 27 Mar 2015 14:57:04 GMT
Thanks for the replies.

After studying the code, I solved it independently like Willem Jiang

public class MyCamelContext extends GuiceCamelContext {
  public MyCamelContext(Injector injector) {

  public void start() {

    // etc.


But then I immediately got stuck with a new problem. I wanted to configure
my application from command line arguments and that seems impossible to do
cleanly with the Camel Guice Main.

In the end, I found an ugly hack which is however quite localized:

public class MyMain extends Main {

  // this is the ugly hack - a static variable that can be accessed
from a Guice Module

  // Guice doesn't run until is called so it's safe

  public static MainArgs mainArgs;

  public MyMain(String args[]) throws InterruptedException {
    mainArgs = new MainArgs();

    addOption(new ParameterOption("c", "conf", "Path to the
application.conf configuration file.", "filePath") {
      protected void doProcess(String arg, String parameter,
LinkedList<String> remainingArgs) {

  public static void main(String args[]) throws Exception {
    Main main = new MyMain(args);


Then I have MainArgsModule which provides MainArgs via normal dependency
injections - this way I can restrict the ugly static access to this one
class while the rest of the app can use dependency injection as usual.

public class MainArgsModule extends AbstractModule {
  protected void configure() {

  public MainArgs createMainArgs() {
    return MainFlowGuice.mainArgs;

java.naming.factory.initial =
org.guiceyfruit.modules = com.myapp.ApplicationModule com.myapp.MainArgsModule

I guess that really not many people use Guice with Camel when there are
such basic issues using it? I am wondering how much more friction there
will be and whether it wouldn't make more sense to simply use Spring as
most do (even though Spring is not my first choice otherwise).

Later I could of course write my own Main for Guice, etc. but I was
hoping to get started rather quickly.


On Thu, Mar 26, 2015 at 9:54 AM, dermoritz <> wrote:

> i just created an ticket with a suggestion:
> --
> View this message in context:
> Sent from the Camel - Users mailing list archive at

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message