wood burning stoves 2.0*
The moose likes Other Application Frameworks and the fly likes What else is Spring good for? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "What else is Spring good for?" Watch "What else is Spring good for?" New topic
Author

What else is Spring good for?

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

So my project currently consists of JSF-Hibernate-SpringDAO. It's one of those projects that seems like it will never be complete. Ok, some background...

When I started working for my current employer on the Help Desk we were keeping track of all our calls using pen and paper. Before you freak out, there were 4 of us and an average call day was about 100 calls. So average 25 calls/day for each person. And maybe 5 of those needed more attention beyond the phone call.

However, I also noticed there seemed to be a lot of calls coming in over the same problems that were being *fixed* for that caller, but never on a more permanent basis. Since I didn't have much else to do at the time I thought why not offer to write an Issue Tracking application for the 4 of us + the techs.

The first version was a Swing application. It worked quite well but since I can never leave things well enough alone and I got tired of updated 15 workstations with revisions, I decided an applet was the way to go. Then I heard about Java WebStart and thought ooooh, I want to play with that. so I converted the applet to an application and deployed via webstart. Worked really well.

Then I started playing around with .NET and since our entire company is right up in Bill Gates arse, I figured, why not learn something else. So I converted the app once again to ASP.NET using C#. Worked great and in fact that version is still in use. However, it is still lacking some functionallity and some things within the company has changed. So a while back I started thinking about converting the app again. Keep in mind I have no one breathing down my back. This is purely my own project. We are NOT a development company. Our IT department is primarily network/PC support. We buy all our software.

So I wanted to really learn J2EE and to make this long story short, it has gone from JSP/Servlet to Struts, back to JSP/Servlets to JSF to Tapestry back to JSF....The data layer has gone from JDBC to Hibernate to JDBC to iBatis to JDBC to Hibernate....

So now I am totally sick of this project and want to get it done. Imagine that. I am sticking with JSF-Hibernate-SpringDAO. The app basically allows you to create tickets and they go in a queue where techs can accept them and take care of them. There is reporting, charts, reminders, yaddda yadda yadda. All that typical stuff.

So, finally, my question is, is there anything else I should be using Spring for that could make this project get done faster/better? Keeping in mind of course I am not going to use their web part. Is there anything I am missing. It seems to me Spring is just beans and reflection. Am I missing something important here?

FYI - sorry about the long post. It's late and I kind of got carried away.


GenRocket - Experts at Building Test Data
Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
I just got done reading a Spring book (Spring in Action) so I'm no expert (and after reading the book...I'm not so sure I want to be...there is just too much to it..not that each part is complicated, but when you sum it all up...it looks like a real beast, and I'm still deciding if I have time to tackle that monster)

Anyway, back to your question...

1) How about security?

Spring integrates with Acegi...although you will have problems with JSF (you can get around them so they say...check out Spring's forum on Acegi Security for some guidance).

2) How about transaction support?

Spring seems to be really good at this, if you can bring yourself to code it all up just right. You can pretty much do anything with Spring that you can do with EJB.

3) How about E-mail? I know you probably already have that, but Spring can do it to.

BTW, you might want to (shields up now) give Java Studio Creator another look and download the latest version . I know you don't like "proprietary" solutions, but it does use the reference implementation after all! Besides, it sure does speed things up (I know the tool can be slow on a slow machine...but it's still a lot faster than coding things up by hand!).
[ March 10, 2005: Message edited by: Darrin Smith ]
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Originally posted by Darrin Smith:
I just got done reading a Spring book (Spring in Action) so I'm no expert (and after reading the book...I'm not so sure I want to be...there is just too much to it..not that each part is complicated, but when you sum it all up...it looks like a real beast, and I'm still deciding if I have time to tackle that monster)


True, there is a lot to Spring. And I can see how you might choke if you try to swallow it whole. But try taking smaller bites and you'll find that Spring is really not that big of a deal.

Start with the core of Spring which is the IoC container. By itself, this piece offers you a great deal of power because it enables you to write code where all of the objects are loosely-coupled (and all the benefits that go with that, including greater testability, easier management, etc, etc). Sure, you can do this without Spring, but Spring makes it nice to be able to configure and wire beans together in one place.

The next bite you should take is Spring AOP. Where IoC lets you decouple your objects that collaborate with each other, Spring AOP lets you decouple your objects from any application-wide services (I'm fighting the urge to say cross-cutting concerns). Of course, the textbook use of AOP is logging, but there are tons of other practical uses of AOP. (I'll come back to this thought in a moment.)

Next, most applications deal with a database at some point. So Spring provides support for most popular persistence mechanisms, including JDBC, Hibernate, JDO, and iBatis.

Spring's declarative transaction support is probably the sweetest bite you'll take. Through AOP, Spring gives you declarative transaction support that is on par with EJB. In fact, Spring's transaction support is actually better than the transaction support given in the EJB spec (and even many application servers).

I know that this is a web frameworks forum, but notice I've not mentioned anything about the web yet? That's because the bulk of Spring's power has nothing to do with web applications. But, there is also Spring MVC, a "framework within the framework", if you will. Spring MVC is a Model 2 web framework in the same spirit as Struts, but with more flexibility. One big complaint about Spring MVC is that it is more daunting than Struts. This is largely because instead of having a single Action class to subclass, Spring MVC has several implementations of its Controller interface to choose from, each one providing a bit more functionality. Once you break it down (as we did in chapter 8 of Spring in Action), it really isn't that bad.

It's important to secure your applications, so next you might want to take a bit of Acegi. Acegi uses Spring AOP to achieve method-level security and servlet filters to achieve URL-level security for web applications. And, you don't need to use Spring MVC to enjoy the benefits of Acegi. In fact, if you have a web application based completely on some other framework (Struts, WebWork, Tapestry, etc), you can still secure it with Acegi even if the application doesn't use Spring anywhere else.

Then there's all of the other stuff like remoting (turn a POJO into an RMI service without changing a line of Java code), EJB support (access your EJBs as if they were a POJO), e-mail, JMS, JMX, etc, etc, etc.

The whole point is that you don't have to take Spring wholesale. You can start out just by exploiting its IoC support. Then, when you're ready, you can start using the other stuff. That's why the Spring distribution comes with one big spring.jar file (if you want to swallow it whole) or several smaller JAR files (to take smaller bites).


Spring in Action - Unleash POJO power in your applications!
Modular Java - Discover the secret weapon to modularity on the Java platform!
XDoclet in Action - Your complete guide to code generation with XDoclet.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

That's great Craig. I bought a copy of SiA last week, but I really just haven't had time to sit down and digest it as a whole. I went through the Database support chapter to get the rolling in my app and that is all I have had time to read.

I have to admit that I felt the same way as Darrin though. At a glance, Spring can look like a monster.
Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
Originally posted by Gregg Bolinger:
That's great Craig. I bought a copy of SiA last week, but I really just haven't had time to sit down and digest it as a whole. I went through the Database support chapter to get the rolling in my app and that is all I have had time to read.

I have to admit that I felt the same way as Darrin though. At a glance, Spring can look like a monster.


Gregg, I know that this is asking a lot ( ) but since you have this working (integrating JSF and Spring's database support) could you provide a tutorial maybe?

There are a LOT of people that I know of wanting to integrate Spring and JSF (using Studio Creator generated code in particular) who would really appreciate this .

I like the Spring in Action book, but after reading it (almost the whole thing), I'm still not sure how to begin. I think I understand the details of many things, but don't have a clear picture of how the parts fit together.

What I got out of it (with respect to using Spring's database support) is that you need to create a config file for Spring that lets it know about the database like this:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value> YOUR DATA SOURCE GOES HERE</value>
</property>
</bean>

Next you need to build your access objects (DAO)...but how that is done I couldn't find in the book. For example, I know you need to have a class that implements the access object like this:

public class SampleDaoJdbcImpl implements SampleDao
{
private JdbcTemplate jdbcTemplate;

public void setJdbcTemplate(jdbcTemplate jdbcTemplate)
{
this.jdbcTemplate = jdbcTemplate;
}
}

but what the SampleDao interface looks like I could not find. Although looking at the implementation you can infer what it looks like to a point, I would think that it might need to extend something as well (BaseDao for example?). Does it?

Then you would need to wire what they call (in my case using JDBC...I know you use Hibernate) the JdbcTemplate like this:

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource"> <--mathes the one defined above
</property>
<bean>

Then you need to build your PreparedStatementCreator methods (details elided).

After that you need to....well, it just keeping on and on (and makes me wonder if it isn't more effort than just doing it yourself withoug Spring...for smaller apps, I bet it would be), but eventually you have the code and the wiring set up to read/write to a database. After that though, how do you go about wiring up the code you just wrote to JSF? And once you have the wiring done (in the faces-config and Spring configuration files I guess) do you make the calls to those objects? Oh, and how to you bundle all of this up so it will dploy correctly!

What I'm getting at is that a tutorial to do this would be nice from someone on this board who can be bugged! I know that there is a tuorial that covers this (Put JSF to Work by Derek Yang Shen) but it leaves out a lot of the gluework (deployment issues).

Anyway, it can't hurt to ask, but as this is asking a LOT, I think we will understand if you (or maybe Craig would volunteer ) don't have the time to do it.
[ March 11, 2005: Message edited by: Darrin Smith ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Darren, take a look at this post by me from last week. I pretty much give all the code and config for using Springs Hibernate DAO support.

I'll look into writing a tutorial. Maybe I should just enhance my current login tutorial using Hibernate and Spring DAO?? I don't know.

As far as integrating spring dao with JSF, it's no differnt that using Spring with anything. There is nothing special you have to do in JSF. And for the record, I am *not* a fan of Java Studio Creator so I won't be writing anything about that except maybe, well, if you don't have anything nice to say...
Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
Originally posted by Gregg Bolinger:
Darren, take a look at this post by me from last week. I pretty much give all the code and config for using Springs Hibernate DAO support.

I'll look into writing a tutorial. Maybe I should just enhance my current login tutorial using Hibernate and Spring DAO?? I don't know.

As far as integrating spring dao with JSF, it's no differnt that using Spring with anything. There is nothing special you have to do in JSF. And for the record, I am *not* a fan of Java Studio Creator so I won't be writing anything about that except maybe, well, if you don't have anything nice to say...



Thanks Gregg, and I'll have a look at that.

BTW, I know that you need to change the faces-config file to use the DelegatingVariableResolver and that isn't a big deal, but what I think is a pain (that JSC eases...I know...not a fan) is bundling and deployment when adding Spring.

In short, a turotial on how you wire it all up (what structure does everything take...where is this config file located...where is that one put...what jars go where for Spring...what files go where for JSF...etc.) would be wonderful.

Oh, by the way...THANKS!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Darrin Smith:



Thanks Gregg, and I'll have a look at that.

BTW, I know that you need to change the faces-config file to use the DelegatingVariableResolver and that isn't a big deal, but what I think is a pain (that JSC eases...I know...not a fan) is bundling and deployment when adding Spring.

In short, a turotial on how you wire it all up (what structure does everything take...where is this config file located...where is that one put...what jars go where for Spring...what files go where for JSF...etc.) would be wonderful.

Oh, by the way...THANKS!


You only have to use the DelegatingVariableResolver if you are using Springs IoC to handle your beans. All I want spring to do for me right now is DAO. I don't need the resolver for that.

Spring in Action really convers deployment. If you read it. JAR files go in the lib folder under WEB-INF, config files go under WEB-INF along side web.xml. There is a ContextListener that comes with Spring to put in your web.xml that loads springs default applicationContext.xml or you can pass the listener params to point to whatever appcontext file(s) you need it to know about. This is all in SiA, just not in one handy location, which I agree would be useful.

If I enhanced my JSF tutorial, I would definatly include deployment. But I'll have to see how much I have on my plate right now.
Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
Originally posted by Gregg Bolinger:


You only have to use the DelegatingVariableResolver if you are using Springs IoC to handle your beans. All I want spring to do for me right now is DAO. I don't need the resolver for that.


Maybe that was covered, but I never caught it. I thought you had to integrate things that way (Spring had to handle the beans taking JSF out of the picutre for bean management). That's one of the BIG picture things that is really important to know too.


Spring in Action really convers deployment. If you read it. JAR files go in the lib folder under WEB-INF, config files go under WEB-INF along side web.xml. There is a ContextListener that comes with Spring to put in your web.xml that loads springs default applicationContext.xml or you can pass the listener params to point to whatever appcontext file(s) you need it to know about. This is all in SiA, just not in one handy location, which I agree would be useful.


Yes Appendix A did cover Setup. Although everything built and deployed (Tomcat expanded the WAR file file) for me...it would not load so...

Anyway, thanks again. I'll keep checking here for it, and once I see it I'll pass along the word (a lot of folks I know are interested).
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
Try taking a look at Spring's Petclinic sample app. It's a simple data access app (no separate business layer) that demonstrates bean wiring, data access through HSQL or MySQL using 3 different strategies (Spring JDBC, Hibernate, & Apache OJB). It also shows declarative transaction management and a SpringMVC web tier.

You might also want to take note of the convenient DaoSupport classes available for each of the persistence strategies. The brevity of the dao methods in HibernateClinic (all are one-liners !!!) really shows off Spring's ability to make using other API's/frameworks much easier. Compare this to using Hibernate standalone and you will see what I mean.

[ March 11, 2005: Message edited by: Ken Krebs ]
[ March 11, 2005: Message edited by: Ken Krebs ]

kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
I too am now working on a sample app that uses Spring-JSF. The app currently is a simple user management system that uses Spring in the business/persistence layers and has 2 implementations of the web tier, one in SpringMVC and the other in Struts using Spring's integration classes. Both web tier implementations do exactly the same thing so it makes for a nice comparison. So now I will also implement a JSF version using the integration library. I will post a notice when I have something available.

There is a link to the JSF-Spring integration (bidirectional) library on the Spring home page.

I should also add this note from the Spring mailing list:

"Note: Spring's JSF support has been developed and tested against JSF 1.1_01,
and it will not work with the earlier JSF 1.1. It does work in MyFaces
1.0.5."
[ March 11, 2005: Message edited by: Ken Krebs ]
Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
Ken,

Thanks for the feedback!

I took a look at Pet Clinic. It looks to be a lot more in depth than what most people with no Spring knowledge are probably looking for.

What we need is something to get us STARTED. A short, SIMPLE tutorial that focuses on one aspect of Spring (database support would probably fit well) and how it can be made to work with JSF.

In other words, a simple straight forward database access sample using JDBC via Spring (something most would have experience with...at least more people than Hibernate or JDO or iBatis or...) that does nothing more than read a row from a table, and write out to another and only uses a few tables.

Maybe something like a password verification (NOT using Acegi) to read the user name and password to compare against what they type in. Once that is verified allow and update to be performed on a second table (notes table or whatever).

Make it a step by step thing:

1) Create the database
2) Add two tables that look like this...
3) Create a project structure that looks like this
4) Create a class for the DAO
5) Create a properties file for JDBC like this (detail everything)
6) Create a configuration file like this (detail everything)
7) Create a JSF page that looks like this...
8) Modify the faces-config.xml file like this...
9) Set up your ant build file like this
10) etc.

I wouldn't add any JUnit testing or anything else that would confuse things (like talking about Hibernate, Spring MVC, etc.). Just the basics...as simple as possible.

If something like that would have existed, it would have saved me a lot of questions (that I still don't have answers for by the way).

Thanks!
 
 
subject: What else is Spring good for?