The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » GlassFish

Thread: Deploying Spring Application in GlassFish

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 9 - Last Post: Mar 20, 2008 2:52 AM by: jwenting
samdoyle

Posts: 189
Deploying Spring Application in GlassFish
Posted: Mar 18, 2008 1:36 PM
  Click to reply to this thread Reply

Can someone tell me why I would want to do this? I don't know much about Spring but I have started working with an application that is based around Spring so was naturally curious to see if anyone was using both of them. I have noticed several posts around people trying to deploy a Spring app. on GlassFish but isn't there a significant amount of overlap here? Anyways I don't mean to start any form of religious war but would be interested in hearing what people have to say.

Thanks

ljnelson

Posts: 268
Re: Deploying Spring Application in GlassFish
Posted: Mar 18, 2008 1:47 PM   in response to: samdoyle
  Click to reply to this thread Reply

On the server side, my EJB3 application uses Spring for configuring all sorts of things. So my EJBs all look up various ApplicationContexts and use them as a sort of...well, I was going to say poor man's JNDI, but the reality is that JNDI in the J2EE environment is really a poor man's Spring. :-)

On the GUI side, I use it instead of resource injection to get access to my EJBs. That lets me test the GUI component with simple pojos.

Hope that helps.

Best,
Laird

ggierer

Posts: 27
Re: Deploying Spring Application in GlassFish
Posted: Mar 18, 2008 2:19 PM   in response to: samdoyle
  Click to reply to this thread Reply

Use Spring when you want a great framework with significant benefits. There are no issues running in GF. We have 4 productions systems running with Spring 2.0 and Spring 2.5 using GFV2. Everything works great.

samdoyle

Posts: 189
Re: Deploying Spring Application in GlassFish
Posted: Mar 18, 2008 2:40 PM   in response to: ggierer
  Click to reply to this thread Reply

Alright so what are the significant benefits? I was using JBoss Seam with GlassFish more so for the presentation side and JavaScript based remoting capabilities while maintaining a conversational scope on a previous project. We were pretty happy with that. I know I really need to pick up a good book on Spring but figured I would ask here.

I still would like to see or hear of a solid example of what Spring can provide me running within GlassFish that I can not get with the application server itself or if something is extremely simplified to the point where it really warrants using Spring inside of GlassFish.

Thanks again.

ggierer

Posts: 27
Re: Deploying Spring Application in GlassFish
Posted: Mar 18, 2008 3:15 PM   in response to: samdoyle
  Click to reply to this thread Reply

Spring is a framework for developing applications. Spring simplifies configuration and provides a multitude of functionality out of the box and with very little coding (inversion of control, aspect oriented programming, data access abstraction, jdbc simplification, declarative transaction management, simplified jndi, jta, rmi, jms, jmx, security, testing etc) You will need to have a look at the spring resources on the web of which there are many. There are also some excellent books and courses (not a plug but I have attended one by Interface 21 and found it very good)

Put simply - most task are done in a few lines of code and a few lines of configuration. It makes programming a lot faster and the code is much easier to test, maintain and enhance.

Spring doesn't care about the environment. You can use Spring in any application server or any java application. Glassfish is a *great* app server and works brilliantly with Spring.

Hope this helps.

samdoyle

Posts: 189
Re: Deploying Spring Application in GlassFish
Posted: Mar 18, 2008 3:25 PM   in response to: ggierer
  Click to reply to this thread Reply

Thanks for your input. Mostly all the things you mentioned are pretty much simplified with JEE5 as well. I guess that has to do for the most part that much of the specification made use of things that were found to be useful in both Spring and Hibernate to meet the ease of use mandate. I'm not too sure on AOP though.

I must say in addition that the tooling support especially in NB is amazing when integrating with GF. Although I'm finding the latest version NB to be a bit unstable hopefully these bugs will be resolved soon.

I definitely want/need to ramp up on Spring so I'm sure I will be finding many similarities.

Thanks for your responses. Greatly appreciated.

ddmarx

Posts: 6
Re: Deploying Spring Application in GlassFish
Posted: Mar 19, 2008 6:07 AM   in response to: samdoyle
  Click to reply to this thread Reply

Java EE 5 was obviously significantly "inspired" by Spring in its efforts to become easier to develop and deploy. Because Java EE 5 did "borrow" so many Spring concepts, the gap in usability between Spring and using Java EE without Spring did narrow somewhat. That being said, there are still nice advantages of using Spring with a Java EE application server.

One nice thing about Spring with a Java EE application server is that Spring often isolates application server-specific functionality in its configuration away from the code itself, allowing the code to remain viable in a Java SE environment, in a Java EE web container (such as Tomcat), or in a full-fledged Java EE application server. For example, Spring's JPA support allows JPA environment-specific characteristics (transaction handling and entity manager access) to appear the same in the code because the differences are handled by Spring via configuration.

As stated earlier, Spring allows simplifies many otherwise verbose APIs. An example here is Spring's JMX support. Spring makes it extremely easy to expose a normal Java class (Spring bean) as a fully JMX-compatible Model MBean without needing to know many specifics of JMX or of Model MBeans in particular. Spring provides similar support for APIs such as JDBC and JMS.

adamc

Posts: 3
Re: Deploying Spring Application in GlassFish
Posted: Mar 19, 2008 7:12 AM   in response to: samdoyle
  Click to reply to this thread Reply

In addition to the increased portability of a Spring-based application (which you may or may not find relevant, depending on your situation), Spring's dependency injection is more flexible than what's available through EE 5's (ultimately) JNDI-based injection. The latter makes it easy to inject many EE 5 components (session beans, data sources, persistence units) into other EE 5 components, but the former lets you inject anything you can configure through Spring into anything else you can configure through Spring.

One common scenario where the difference gets important when you're injecting references to expensive-to-initialize "singleton" objects, for example; there's no straightforward way in EJB "3.0" to define such an object as an EE component, while Spring makes that sort of thing easy. Of course, your application's design may not depend on such objects. That's one of the reasons the @Singleton annotation is slated to be in EJB 3.1.

samdoyle

Posts: 189
Re: Deploying Spring Application in GlassFish
Posted: Mar 19, 2008 9:10 AM   in response to: adamc
  Click to reply to this thread Reply

Great and thanks for the feedback. Much appreciated.

jwenting

Posts: 478
Re: Deploying Spring Application in GlassFish
Posted: Mar 20, 2008 2:52 AM   in response to: adamc
  Click to reply to this thread Reply

what you fail to mention is that you can get the best of both worlds by injecting EJBs through Spring, getting all their functionality in your client code without having to know you're even using EJBs.




 XML java.net RSS