aspose file tools*
The moose likes Spring and the fly likes Why Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Why Spring" Watch "Why Spring" New topic
Author

Why Spring

Rahul Dayal Sharma
Greenhorn

Joined: May 23, 2012
Posts: 10
Hi Ken Rimple & Srini Penchikala,
I am new to the entire Framework concept, I would like to ask- How and why do you use frameworks like JSF, Spring and Hibernate and also the real concept behind reflection to manage java Objects. And what's its use in J2SE.
Ken Rimple
author
Ranch Hand

Joined: Jul 20, 2010
Posts: 63

This is far too big of a topic to cover in a blog post...

You use frameworks to provide the 'boilerplate' or repetitive operations you normally would have to do by hand. Some examples of those tasks:

- handling web traffic to your java objects
- rendering pages of output as HTML - what format do you convey them in, etc - JSF and JSP are two approaches, but also velocity templates and way back when even XML/XSLT have been used, so don't re-invent the wheel...
- handling security
- handling transactions (rolling back with failures)
- logging (log4j is a very popular logging API / framework)
- configuring applications

etc...

So there are application development platform frameworks (Grails, Rails), application infrastructure services (Spring, Seam, Guice) that provide component wiring and easy testing, security frameworks (Spring Security, Java EE security), even transaction management frameworks (JTA comes to mind).

Some advocates of languages such as Scala feel that frameworks are a bad thing and that you should write that as code. I'm not convinced myself.

As for Spring...

There are plenty of presentations on why to use Spring - actually Rod Johnson lays it out nicely in his original book on Pro Java EE (forgive me, I don't remember the full title).

The quick answer is that Spring is forward-looking, always trying to find the most elegant and productive way of doing things. Java EE 6 owes a lot to Spring and also to Ruby on Rails, and other frameworks. In some ways, Java EE 6 needs less configuration than Spring does for the base case of providing web apps with services and repositories, but that is the basic use case. Spring is so much more than just a basic web application or service application container. There are tons of useful APIs, and you get very productive very quickly once you learn how to work with dependency injection and with the Spring component APIs and factories.

Hibernate is becoming yet another JPA container too, so you can put it behind a JPA 2 API and use it as your Java EE persistence layer. Spring lives in that world, so you can use hibernate behind JPA (or even naked, with the Session API) with Spring. But you're not limited to that. You can use Spring Data to connect to a number of NoSQL databases. You can use Spring with MyBatis if you like SQL Mapping rather than ORM. Heck, you can do some JDBC code very efficiently with the JdbcTemplate API. Spring does not lock you in to anything, but opens the possibility to efficiently write software against a wide range of other APIs simply.

Spring is also container neutral. It will run in a simple servlet engine all the way up to WebSphere and WebLogic and JBoss and doesn't make any choices for you. It will use JDBC connection pools or app server JNDI data sources for database connectivity. The security, transaction management and monitoring via JMX are all platform agnostic. They don't care what you run on, but will integrate with much of it if needed.

Hopefully that gives you wide enough of a swath of information to start with.

I would read up on Spring itself - go to springsource.org/documentation and download/read the Spring Framework documentation for 3.0.x - if you're already a Java developer, it will be an easy (and illuminating) read. Sure, some of this seems like work compared to setting up the most recent Java EE 6 platforms, but it isn't really that bad and gives you so many options on how to write your applications that you don't feel limited by Spring, rather supported by it.

Best,

Ken

PS - I've worked on a lot of other software that isn't Spring in my past, in my recent past have been a huge fan of Grails, and currently our company web site is Rails 3.1, so I have some comparative background - I have no complaint with any of these things, but if I'm in an enterprise the gotos would be Spring and/or Grails and/or Roo for first choices - it's all Spring and compatible with Java. It's all horses for courses, it's what makes the best sense for your organization.


Ken Rimple
ken.rimple@gmail.com
Co-author, Manning Spring Roo in Action
I teach for Chariot Solutions (Spring, Maven, Hibernate, other courses). Schedule here
Rahul Dayal Sharma
Greenhorn

Joined: May 23, 2012
Posts: 10
Hi Ken,
Thanks for the detailed explanation of Spring. Is your book based on teaching Spring only through coding or is it focused on some feature of an IDE as well. Also, I know J2SE and am learning J2EE, so what concepts should i be concentrating on in order to learn Spring ?
Ken Rimple
author
Ranch Hand

Joined: Jul 20, 2010
Posts: 63

We teach Spring features enough to understand what Roo is doing with them. I highly suggest Craig Walls' Spring in Action if you want to learn Spring.

Roo is more than just a RAD platform, but also less of a complete solution than something else like Grails. It doesn't hide Spring from you, therefore you should really study Spring in order to get the most from it.
sachin pachpute
Ranch Hand

Joined: Aug 05, 2004
Posts: 35
Hi Ken,

I am completely new to Roo so am I missing a big thing here?

What does is mean to a developer who is working on Spring3 MVC & hibernate with Eclipse IDE and does not know Roo? I have started developing application a month back and now came across this post.

I am still not getting my head around on how can I make use of Roo in my application(or should I at the first place)?
Do I have to start all over if I want to learn Roo?


Thanks
Ken Rimple
author
Ranch Hand

Joined: Jul 20, 2010
Posts: 63

sachin pachpute wrote:
What does is mean to a developer who is working on Spring3 MVC & hibernate with Eclipse IDE and does not know Roo? I have started developing application a month back and now came across this post.


It means that you'd have to adjust your coding a bit to work inside of a Roo platform. To wit:

- You'd need to use JPA 2, with a Hibernate provider, rather than Hibernate. Roo is a JPA platform. So you'd use EntityManager rather than SessionFactory & Session.
- You'd be using JSPX if you use the Spring Roo web application tier. Spring Roo really wants you to use that.

Beyond that, I'm beginning some EARLY work on a web mvclite add-on that would only use JSP tags and JSP pages, one-way scaffolding (generate but not sync) and removes all hints of client-side code and validation (only server-side).

I would like to see this through to a 1.0 version, and since my project is hosted on CloudBees as an open source project, I will be releasing it to everyone as research. I would at least try to do this and then show it to the Roo team, emphasizing that this should be a built-in choice so that we don't have to get Dojo + all the other heavy duty selections made for us initially.

Ken
Rahul Dayal Sharma
Greenhorn

Joined: May 23, 2012
Posts: 10
Hi Ken,
I will check out that book, but i would like to know about the prerequisites for Spring and of course Roo
Ken Rimple
author
Ranch Hand

Joined: Jul 20, 2010
Posts: 63

Rahul Dayal Sharma wrote:Hi Ken,
I will check out that book, but i would like to know about the prerequisites for Spring and of course Roo


Spring:

Core:
- Solid Java OO development techniques - interface driven development
- Some knowledge of the concept of reflection and what it does
- A background in Java EE concepts such as transaction management and security
- Understanding of the proxy design pattern - Spring uses dynamic proxies to wrap beans with transaction, security, jmx, and other support

Web (MVC):
- Helps to have prior use of a model-view-controller patterned web framework such as Struts, but you can learn in in the context of Spring MVC
- Comfort with annotation-driven Spring bean configuration - Spring MVC is annotation-driven, so you'd use annotations such as @RequestMapping, @Controller, etc.
- Some web application server knowledge - how to deploy wars, for example
- Knowledge of a build tool such as Ant or Maven - both of which can be used to put together Spring builds

Spring DBMS support
- Knowledge of JDBC
- Knowledge of a database, such as PostreSQL, Oracle, Sybase, etc...
- Knowledge of how to connect to a database normally (connection settings such as username, password, server, JDBC URL, etc)
- for ORM such as JPA or Hibernate, you'll need to learn how those are programmed, but Spring can make it easier for you
- for JDBC, Spring has a fantastic tool called the JdbcTemplate that simplifies JDBC code to one or two lines plus a handler method - no more try catch code!

The same pattern is true for any technology Spring exposes. It helps to know it, to see examples natively in it, so that you can see how Spring approaches providing those services to you. And the manual for Spring itself - the Spring Framework Reference Guide - is really, really good. One of the best.

Spring Roo won't be as useful to you unless you know the above to some degree. In a way, it's a power tool, one that can make your life easier. Especially if you have a lot of repetitive tasks, or have to create a lot of projects in your organization and want to set some standards, it's great. But it needs some focus by the developers using it, or it will just be a code generation tool.

So, start w/Spring, but as you're learning Spring, try creating projects in Spring Roo that have the features you're researching. For example:

For JMS, go ahead and use jms setup to set up a JMS server inside of your app, then write JUnit integration tests to learn how to post messages and consume answers.

For JDBC, go ahead, set up a simple Roo project, and inject the dataSource into an integration test. Then create a JdbcTemplate instance (it takes the dataSource as a constructor) and play with it.

etc...

Hope this helps.

Ken

-
Rahul Dayal Sharma
Greenhorn

Joined: May 23, 2012
Posts: 10
Thanks for the list of requirements sir,
I am making a project in Core java, where I have to make an attendance application residing on the main network ( or rather a server ) and whosoever has access to that network can access the application, open his account and enter his attendance date and time. I would like to know, if there is any way I can create something with the functions similar to the connection pool using the frameworks in order to enable multiple users to access that app and enter his attendance which would be stored in Microsoft Excel using JDBC.
Ken Rimple
author
Ranch Hand

Joined: Jul 20, 2010
Posts: 63

Rahul Dayal Sharma wrote:Thanks for the list of requirements sir,
I am making a project in Core java, where I have to make an attendance application residing on the main network ( or rather a server ) and whosoever has access to that network can access the application, open his account and enter his attendance date and time. I would like to know, if there is any way I can create something with the functions similar to the connection pool using the frameworks in order to enable multiple users to access that app and enter his attendance which would be stored in Microsoft Excel using JDBC.


I am a bit confused by your question.

Do you want to build a swing/java fx(Java graphical) application that would run on a client, or a server-side application with a web interface? Excel is not a safe destination for a multiple user database. You could give people download-only spreadsheets easily with Spring MVC using JExcel or Hssf from POI. But apI would use a real database, like postgres or mysql, or even derby/hsql, and use at least a c3p0 or Apache DBCP for the connection pool. Both of those can be mounted as datasources in Spring.
Rahul Dayal Sharma
Greenhorn

Joined: May 23, 2012
Posts: 10
Well I am supposed to make it using core... I want to just place it on the network and enable people to access it through a connection to that network without installing any apps on the users pc/laptop. And I am using excel because the people who will be taking out the attendance data each day are not that well acquainted with databases like Derby, Oracle, MySQL, so it would be preferable for them to attain the info easily in a readable format like Excel.
 
 
subject: Why Spring