First of all.
If you will still be using different spring libraries I would stick with spring DI. Whoever will be maintaining the application will need to read and understand the spring configuration anyway so there is not that much gain in migrating the DI framework to guice.

If you have no other choice here are some entry points to read up for your problems:

2)
The guice servlet extension - it shows how to create the injector and how to execute code
 - at startup
 - before/after every request:
https://code.google.com/p/google-guice/wiki/Servlets
https://code.google.com/p/google-guice/wiki/ServletModule

3)
There are several ways you can achieve this. But all of them seem to scream "service locator pattern" (https://en.wikipedia.org/wiki/Service_locator_pattern)
If possible I would try to distinguish the different the different entry points to your factory as early as possible (i.e. in a servlet filter).
Once you have them distinguished you can use different implementations which have only their dependencies injected.
If this is too much work you can use either injector.getInstance(...) or you can have the required Provider<...> injected into your factory.

What also could be of interest (but does not solve the particular problem you describe) is assisted injection
https://code.google.com/p/google-guice/wiki/AssistedInject






On 05/29/2014 07:49 PM, Chetan Kinger wrote:
I am currently working on a task that involves migrating a standalone app to our company's in house framework. The in house framework uses Guice for dependency injection. The standalone app that needs to be migrated to this framework uses Spring, Spring-JMS and Spring Batch. Also, the standlone app needs to be converted to a web app and deployed in an app/web server. 

The catch here is that my Spring beans will need to be injected with the Guice created objects of the framework classes so there is going to be a mix and match of Spring and Guice managed objects in my app. 

I have taken a look at SpringIntegration and managed to understand how to bind all my Spring managed beans in a Guice module. I also took a look at the  @Named Guice annotation that can be used to inject the Spring beans with Guice. 

I now have the following questions :

1. Will the Spring beans bound in Guice using SpringIntegration remain Singleton or will I need to explicitly add the @Singleton annotation above all my Spring managed classes so that Guice treats them as singleton? 

2. In the current standalone application, I programmatically launch my Spring batch jobs and start a JMS listener in the main method . I now need to deploy my standalone application as a web app in a web server. I need to launch my Spring batch jobs and then start the JMS listener automatically after the app is deployed. To launch my Spring Batch jobs and JMS listener, I need Guice to load my Guice module that will bind my Spring JMS and Spring Batch beans. In a standalone app, the main method would have been a good enough place to create an injector and then launch the Spring batch jobs and start the JMS listener. Where do I create an injector and start my jobs and listener in case if a web app? Note that I want to listener and the jobs to be started automatically. Also, I am not going to do any Web related stuff other than deploying standalone app as a web app in a web server.

3. I currently have a Simple factory in my standalone app that has a creator method that takes a parameter. The create method gets the appropriate bean from the Spring context based on the input paramater passed at runtime. What is the Guice way of creating cresting a parametrized factory?  

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/d/optout.

Reply via email to