Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 65C6B17E9B for ; Fri, 27 Mar 2015 14:58:11 +0000 (UTC) Received: (qmail 50485 invoked by uid 500); 27 Mar 2015 14:58:10 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 50440 invoked by uid 500); 27 Mar 2015 14:58:10 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 50429 invoked by uid 99); 27 Mar 2015 14:58:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Mar 2015 14:58:10 +0000 X-ASF-Spam-Status: No, hits=2.8 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,URI_HEX X-Spam-Check-By: apache.org Received-SPF: error (athena.apache.org: local policy) Received: from [209.85.213.176] (HELO mail-ig0-f176.google.com) (209.85.213.176) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Mar 2015 14:58:05 +0000 Received: by igbqf9 with SMTP id qf9so21996017igb.1 for ; Fri, 27 Mar 2015 07:57:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=EhojD+c+aevZ+Gdc7CKgP9r5wgYiI//YUpVVtX7lYP4=; b=aJHPjPWo52BOsQgO+46W3i9g+mozgJBULZWGIK2hRuqmUr5ckBj0fu12C4rdKOv4Yr QG2rhzEBzIQ/UHOkl3g+5UsE7r8blANduUN7iZHkpYkqLpJTJSaxyY/WZJaBE/y5cpLS QdO4VVrceECrtIzrRMzJV9qJ4Q6nvF10GHaHic5Fa2r/QwSrOPuS1RBqw//I02a4Wtg4 zO1fv8lHrJxpCQ99ZqHV1wOYOp/YvyJMp7fYmZnn7No1YREjzrdx+VXF8FzVy3Lw73v/ UpVvjEEamD38KhhIgAIPiO0jn98BDu6JDatE9SFtvJ7qwgSSlEzT+MMbhR2Lt1dKHIo9 BIxA== X-Gm-Message-State: ALoCoQkDNX2JpWYXyXWV9UN/HLY1W6PkDkc6V5JNxZY4yJeY9DAmmuo+o8IX6snaUqMYBroIzIT/ X-Received: by 10.107.164.140 with SMTP id d12mr30238194ioj.13.1427468244850; Fri, 27 Mar 2015 07:57:24 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.247.9 with HTTP; Fri, 27 Mar 2015 07:57:04 -0700 (PDT) In-Reply-To: <1427363676518-5764818.post@n5.nabble.com> References: <1427361321880-5764817.post@n5.nabble.com> <1427363676518-5764818.post@n5.nabble.com> From: Jakub Kotowski Date: Fri, 27 Mar 2015 14:57:04 +0000 Message-ID: Subject: Re: Setting up CamelContext with Guice To: users@camel.apache.org Content-Type: multipart/alternative; boundary=001a1141c7b4a9d1df0512465949 X-Virus-Checked: Checked by ClamAV on apache.org --001a1141c7b4a9d1df0512465949 Content-Type: text/plain; charset=UTF-8 Thanks for the replies. After studying the code, I solved it independently like Willem Jiang suggests: public class MyCamelContext extends GuiceCamelContext { @Inject public MyCamelContext(Injector injector) { super(injector); } @PostConstruct public void start() { setTracing(true); // etc. super.start(); } } 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 main.run(args) is called so it's safe public static MainArgs mainArgs; public MyMain(String args[]) throws InterruptedException { mainArgs = new MainArgs(); mainArgs.setArgs(args); addOption(new ParameterOption("c", "conf", "Path to the application.conf configuration file.", "filePath") { @Override protected void doProcess(String arg, String parameter, LinkedList remainingArgs) { mainArgs.setConfFile(parameter); mainArgs.loadAndValidateConf(); } }); } public static void main(String args[]) throws Exception { Main main = new MyMain(args); main.enableHangupSupport(); main.run(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 { @Override protected void configure() { } @Provides public MainArgs createMainArgs() { return MainFlowGuice.mainArgs; } } jndi.properties: java.naming.factory.initial = org.apache.camel.guice.jndi.GuiceInitialContextFactory 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. Jakub On Thu, Mar 26, 2015 at 9:54 AM, dermoritz wrote: > i just created an ticket with a suggestion: > https://issues.apache.org/jira/browse/CAMEL-8555 > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Setting-up-CamelContext-with-Guice-tp5764709p5764818.html > Sent from the Camel - Users mailing list archive at Nabble.com. > --001a1141c7b4a9d1df0512465949--