How can I work with Spring and Guice beans in a single web application such that a Spring bean needs Guice to inject some dependency into it?
I am currently working on a task that involves migrating a standalone app to our companies 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 and Spring - JMS. Also, the standlone app needs to be converted to a web app and deployed in an app/web server.
The catch here is that the standalone app classes are Spring beans whereas the framework classes primarily contain a lot of Guice injections all over the framework.
Edit :
Based on the comments on this question, I have taken a look at SpringIntegration and I understand that I will need to bind all my Spring beans in a Guice module. I have the following questions :
Will all the Spring beans bound to Guice using SpringIntegration remain as singleton or will I need to explicitly define them as Singleton using #Singleton from Guice?
What would be the right place to create an injector out of my Guice module and thus initialize the Guice module? Note that my app is going to be a web app that does not use any web related stuff.
Related
I have a scenario that Jersey 2.13 (with HK2 as DI) is loaded up in Tomcat and on the same JVM (I start it up from a startup servlet) a netty-socket-io server is running. I want this second server's methods to have access to the injected classes that the rest of my web app is using and I wouldn't like to introduce another dependency injection framework just for that.
I read that you can get a ServiceLocatorProvider in Jersey for doing this here but you need to have a context provided while my methods are completely separated.
As I am trying to learn some framework J2EE, I am studying on spring framework.
The thing that confused me in some tutorial they mention Spring MVC as a part of the spring framework. But at some place they mentioned as like a different and independent framework. some people even compare Spring MVC with Struts (which is another framework as i understand ).
Now how actually should i take Spring MVC in mind as a different framework like Struts or as a part of Spring?
Spring has incredibly grown in the last decade, so nowadays the single word Spring means different things depending on the context in which it is used. In such context might be used the following Spring projects.
One of these projects is the Spring Framework: an open source application framework and inversion of control container for the Java platform which offers lots of features:
Dependency Injection
Aspect-Oriented Programming including Spring's declarative transaction management
Spring MVC web application and RESTful web service framework
Foundational support for JDBC, JPA, JMS
Much more...
each one of these features is designed in a Spring Framework's module grouped in layers, so among others, you can find:
in the core layer
The Core and Beans modules provide the fundamental parts of the framework, including the IoC and Dependency Injection features.
...
...
in the web layer
...
The Web-Servlet module contains Spring' s model-view-controller (MVC) implementation for web applications. Spring's MVC framework provides a clean separation between domain model code and web forms, and integrates with all the other features of the Spring Framework.
...
..
Your question
Now how actually should i take Spring MVC in mind as a different framework like Struts or as a part of Spring?
Both are right because of what summarized above: Spring includes Spring Projects and one of them is Spring Framework which contains Spring's MVC framework.
So if you think the single word Spring both as the most general and as the Spring Framework, Spring MVC is part of Spring.
Moreover you may consider Spring MVC like Struts, because Spring's MVC framework application domain is extremely closed to the Struts one.
I think your confusion comes up from considering a part (Spring's MVC framework) as different from the whole (the most general single word Spring or the Spring Framework) in which the part may be thought included.
Spring in common meaning is framework provided by spring-core artifact [http://mvnrepository.com/artifact/org.springframework/spring-core]. Contains IoC, Dependency Injections and other stuff.
Spring MVC using Spring to bootstrap application context, and add some functionality and features specified to MVC. You should think about Spring MVC as 'plugin' or 'extension' of Spring.
Spring is a Java EE-like stack. The core Spring framework provides Dependency injection, AOP, JDBC helpers etc. Also there are a couple of sub-projects: Spring MVC, Spring batch, Integration etc. (See the full stack here: http://spring.io/projects)
Yes Spring MVC is veri similar to Struts, as both are action oriented MVC frameworks. Usually the sub-projects depend on the core and not on the other sub-projects.
The main point is that Spring is a stack of technologies.
My ear is using CDI but I'm running into known memory leaks. Rather than drop dependency injection all together, I'm wondering if it's possible to replace the CDI code with Guice code.
I'm using the Stripes framework, Web Services and Jersey 1.x. How can I get Guice to manage all these end points?
To get Guice working in web services
To get Guice working in Stripes framework
To get guice working in Jersey 1.x
Errai "rocks" web development using GWT. However I want to leverage on my Spring code base to be used in my web application back-end services.
Service like:
#Service
public class ProductServiceImpl implements ProductService {
// ...
}
Where I can call this service from the GWT UI side, what are the options when I am already using JBoss Errai?
here is the example of how to integrate errai services with spring
1.- You can inject dependencies through some CDI implementation (for JBoss AS it uses Seam).
Or 2.- you can use Seam, to activate the spring application context, if you insist to use spring.
In the first option, you can use some errai archetype to obtain a basic skeleton of an application.
In the second option... you can the same thing, but you have to read about seam-spring context integration.
Link for the archetype
Link for spring integration
I need to start developing applications using the Spring framework, and am wondering what tools I need to download to have me up and running.
On the SpringSource website I am seeing all these applications to download and I am wondering, do I really need all this? And what versions should I use, especially for Spring Framework?
Spring Framework
SpringSource dm Server Samples
Spring Security
Spring Web Flow
Spring Web Services
Spring Dynamic Modules
Spring Integration
Spring Batch
Spring.NET
Spring JavaConfig
Spring LDAP
Spring Extensions
Spring IDE
Spring BlazeDS Integration
SpringSource Bundlor
Spring ROO
What other applications do I need to download (eg. Struts, Glassfish, Apache, etc.)?
This depends on what you want to use Spring for. Typically that's Web applications. If so you only need two things:
Spring framework (with minimal dependencies); and
A servlet container (eg Tomcat) or a full-blown application server (eg Glassfish, JBoss).
Everything else is optional. I believe the only required dependency is Apache Commons logging. Depending on what features you use, you may well need more.
If so, here is a [tutorial][1] that creates a barebones Spring MVC project. There are countless others around for that and other topics.
It's entirely possible to use Spring in, say, a Swing application in which case you obviously don't need a servlet container.
All you need from SpringSource is the Spring Framework.
Spring 3.0 is on the way, but for now, use 2.5.6.SEC01, the current production release.
You can get started with a simple servlet container (ie: Tomcat) rather than a full blown application server (eg: JBoss, Glassfish).
The Spring Framework comes bundled with jars for web development - ie: spring-web and spring-webmvc.
See #117535 for a simple example of using Spring MVC.
It mainly dependent on what you need Spring for. Each and every piece of Spring can, actually, be used in separation from the rest. You may use it only for IOC, in this case you don't need, for example, MVC and Servlets, etc...
The easiest way to start is to dowload the main package from http://www.springsource.com/download/community?project=Spring%20Framework
You can use Spring from any IDE
The best way is to use Maven with your project. Basically all you have to do is edit your pom.xml file and tell it that you want to use Spring. Then when you compile your code, Maven will go out and automatically download the Spring libraries you need from their public repository.
Here's an example:
http://pookey.co.uk/blog/archives/63-Getting-started-with-Maven-and-Spring.html