How can I use Guice in Glassfish 3? - java

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

Related

How Apache CXF technically integrates with Spring Framework

I know I could use Apache CXF with Spring by declaring certain CXF beans, but want to know how these framework technically integrates with each other.
Does CXF libraries provide some service provider interface known to Spring, so Spring scans for this, instantiates the service and takes control of it? Or does CXF implement some other standard mechanism for Spring integration? If so, what is this standard?
Or does CXF library expose Spring annotations / bean declarations to participate in the Spring configuration when in the classpath?
Where I can find the exact sequence of how Spring takes control of CXF from having both of these frameworks on classpath and the necessary configuration to both of them running together? Which configuration is scanned in which side, what API's are called by which and so on.
CXF's is the Bus and its default implementation is SpringBusFactory which scans for certain Spring xml bean configuration files. You can find more information in http://cxf.apache.org/docs/cxf-architecture.html#CXFArchitecture-Bus or by looking at the sourcecode: https://github.com/apache/cxf/blob/master/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java

Example for using Guice with Endpoints Frameworks for App Engine version 2

Does anyone know a good example for using Guice with the new Google Endpoints Frameworks for App Engine Version 2.
In the Documentation
Migrating to Endpoints Frameworks for App Engine
Guice is mentioned at the end of the docu. But i am missing a full example with web.xml, appengine-web.xml, Module class and Eclipse.
Add endpoints-framework-guice as a dependency.
Add an instance of EndpointsModule to your GuiceFilter.
Additionally bind GuiceFilter to /_ah/api/* in web.xml to work around a legacy URL resolution issue.
Please review the Using Guice with Endpoints Frameworks guide.
The example demonstrates how to use Endpoints Framework v2 with Guice.

Embed Grizzly (glassfish) Servlet Container with Spring Boot Java

Spring boot by default uses Tomcat as an Internal Embedded Servlet Container .
It has also got support for Jetty and UnderTow.
I have build a Restful Application using spring boot . But now i need to deploy it on Grizzly (Glassfish) Servlet Container .
How do i embed my application to run on grizzly as spring dosen't have support for the same.
https://github.com/spring-projects/spring-boot/issues/5015.
Please help as i researched a lot on thistopic but i coudnt get any link that shows how to embed a new Servlet Container for our spring boot app that spring dosent have support for.
Thanks
The Grizzly website states that Grizzly's servlet support is incomplete:
This is not a Servlet compliant implementation and as such, not all features exposed by a typical Servlet container are available here.
I haven't seen anywhere that expands on what those missing features are, but there's a good chance that what you're trying to do isn't possible without filling in some gaps in Grizzly's servlet support.
Assuming that it is possible, you need to write Grizzly-specific implementations of Spring Boot's EmbeddedServletContainerFactory and EmbeddedServletContainer interfaces. This is a fairly significant amount of work so, before undertaking it, I would ask yourself what you will gain by being able to use Grizzly as an embedded servlet container versus using Jetty, Tomcat, or Undertow which are already supported out of the box.
If you do decide to tackle this, reading the source code for the existing implementations for Jetty, Tomcat, and Undertow is the best way to learn about what needs to be done:
JettyEmbeddedServletContainer.java
JettyEmbeddedServletContainerFactory.java
TomcatEmbeddedServletContainer.java
TomcatEmbeddedServletContainerFactory.java
UndertowEmbeddedServletContainer.java
UndertowEmbeddedServletContainerFactory.java
As pointed by #Andy there is no support for Spring Boot and Grizzly .
Finally i moved to Spring MVC for the same.
Here is the working repo where i embedd Spring MVC with grizzly.
Hope it helps someone.
Link
There is now a third-party implementation of a Spring Boot starter for Grizzly which has specific implementations of the Spring Boot's EmbeddedServletContainerFactory and EmbeddedServletContainer classes for Grizzly.
Besides that it also offers JSP support through Tomcat's Jasper JSP engine, simply by specifying an additional dependency. You can find the project at GitHub and it is also listed in the Spring Boot starters list.

Using Guice and Spring together in a web application.

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.

What do I need to download to start developing apps using the Spring framework?

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

Categories