Getting started with Spring 3 Web MVC - Setting everything up - java

I'm trying to get started with JAVA/Eclipse/Spring MVC but can't seem to find a "dummies" or "step-by-step" guide for setting everything up and creating the simplest proof-of-concept application.
I found http://static.springsource.org/docs/...-step-by-step/ but there seem to be differences between Spring 2.5 and Spring 3 so i'm looking for something for Spring 3.
Also, the tutorial for Spring 2.5 focuses on building the application usign Ant - This i will certainly be doing for releasing but when working within Eclipse i want to have set up the project so that i can use breakpoints/debugging and this is not covered at all.
I've downloaded Eclipse, Tomcat and the Spring 3 Framework but that's about it and within the downloaded Spring Framework documentation it states:
2.3 New getting started tutorial
There is now a new getting started tutorial
for developing a basic Spring 3.0 MVC
web application. This tutorial is a
separate document that can be found at
the Spring Documentation page
However, i can't seem to find such a tutorial on the linked page. My main problem at the moment, as seems to be the case for many people trying to get started with Spring, is that i can't seem to get everything set up.
I've got a copy of Expert Spring MVC and Web Flow and i've also found this tutorial but i don't know if the setups they describe are still relevant and whether they will allow debugging.
Can anyone please give some direction?
Thanks

Get the mvc-basic or the petcare sample apps from the Spring Samples SVN repository. These samples have been updated to Spring 3.0 and are directly importable & runnable with SpringSource Tool Suite.

I am also started to learn Spring 3.0 and i am not getting any help means any tutorials. but i find this site http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html and its very help full for start up development. but still i am finding another example so that i come to know more about it
if anybody knows some example in spring 3.0 then please provide me.
Thanks
Dhrumil Shah

These days, I think the easiest way to find out how to set up a spring application is by trying out Spring Roo. It may not be what you finally end up using when coding your project but it shows you exactly how to setup a Spring MVC web app.

I've also been looking all over for a full Spring MVC 3.0 tutorial with Eclipse that I could follow and haven't had too much luck in my research. The closest and most helpful example that I could find is here: http://krams915.blogspot.com/2011/01/spring-mvc-3-hibernate-annotations.html. This is also a maven project, but I was able to move some things around in my Dynamic Web Project within Eclipse and at least get the initial page to come up. Currently, I'm having issues with spring finding my controller class, but I think that's a part of changing the configuration files to meet my project needs. But try it and I hope it works for you!

I found these tutorials really helpful:
http://krams915.blogspot.ch/p/tutorials.html
I wanted to use REST and MongoDB and followed following tutorial with success:
http://krams915.blogspot.ch/2012/01/spring-mvc-31-implement-crud-with_4739.html
I hope it helps. I know how you feel :) Had the same issues. But it's worth sticking with Spring and learning it. It's a great framework once you know it.
Personally I made not so good experiences using Spring Roo. It can help you maybe a little bit for investigation how to setup a project but if you are new to Aspect Oriented Development you'll have a hard time figuring out what Spring Roo does. It can help you to setup a project really fast and easy but if you don't understand what's behind the facade it's hard working with it. This is not really for a beginner and no necessity for any project. But Aspect Oriented Development is worth wile learning and can be very useful to avoid boiler plate code.

Another route might be use appfuse, specifically using maven to generate the application template code from the appfuse archetype. E.g. this link.

There is a major difference in Spring 2.5 and Spring 3.x, Spring 3 or later introduces Annotations based bean wiring and dependency injection.
The nice step by step tutorial i found is http://www.journaldev.com/3531/spring-mvc-hibernate-mysql-integration-crud-example-tutorial

Related

Spring project without xml

I'm new to Spring.
The goal is to learn Spring, to use Spring as a production application as it is industry standard.
The requirements of the app:
Hibernate, Security, MVC, RESTful, DI, etc.
The other Spring frameworks might be added in future.
I'm reading "Spring in Action. Third Edition." by Craig Walls.
He gave the examples how to use annotations, but anyway .xml is used.
I'm wonder if I can write the application using only java classes to configure all modules in the application.
I found Spring Boot gives ability to develop not using xml files. However I read the article http://steveperkins.com/use-spring-boot-next-project/ and author said Boot is not ready to be used for production applications.
As far as I understood Boot hides all config work from me. Also my concern is that in future java-developers who knows Spring won't be able to deal with Spring Boot and I wouldn't find proper engineers for the project.
Based upon this I have the following questions:
Is it possible to avoid using xml in Spring or better to mix xml files and annotations?
Is it easy for Spring developers to work with Spring Boot?
Am I able to learn Spring using Spring Boot?
Is Spring Boot is mature enough to use it in production?
Is it possible to avoid using xml in Spring or better to mix xml files and annotations?
Yes, it is. Spring now promotes Java configuration, and it's perfectly doable (I'm doing it) and even easy to only use Java to configure your Spring app. Even without using Boot.
Is it east for Spring developers to work with Spring Boot?
Why wouldn't it? It's well documented, and is based on Spring best practices.
Am I able to learn Spring using Spring Boot?
How could I answer that. Try doing it, and you'll see if you're able or not.
Is Spring Boot is mature enough to use it in production?
Yes, it is. The articleyou linked to is one year old. Spring developers have worked a lot on Boot since then. And Spring uses Boot internally to host their own spring.io web application. See https://github.com/spring-io/sagan
JB Nizet answered 3 answers very clearly. Just an addition about production readiness from my side. We are currently using Spring Boot for an application which we intend to move to production. There has not been any issue till now in prototyping and testing phase. It is very convenient and avoids boilerplate and gives production ready, standalone jar file with embedded server. You can also chose to build war file if you prefer.
"Am I able to learn Spring using Spring Boot?"
As you mentioned that you are new to Spring, it would probably be easier for you to pick up Spring Boot quickly.
To get started, if you are interested, following is the link to a webinar by Josh Long which gives you a really good insight of how easy it is to pick up Spring Boot:
https://www.youtube.com/watch?v=eCos5VTtZoI
I don't know much about Spring Boot but I know pretty much about spring.
First of all you can use both annotations and xml configuration file/s in the same project. That is the most common way as far as I know.
There is also JavaConfig configuration option in which you don't use any xml files instead you use ordinary java class with #Configuration annotation. I didn't use and not saw much usage also.
You can make a spring webapp without any xml, although spring security was ugly to configure last time I looked at that. For a webapp you need to implement WebApplicationInitializer, create an application context and register your #Configuration file(s) with the context. Then you register the dispatcher servlet and you're all set!
I was nearly in the same boat four months ago when I started working on my web app & chose Spring as the platform after evaluating many choices. I also started with Spring in Action but got frustrated when the examples provided by the author didn't work (Spring basic MVC app not working). Since I was just starting, I was looking for some very basic but working examples. But unfortunately, most of the examples which came along with Spring text books, didn't work straight out of the box.
I would like to suggest few Spring resources which I found useful for starters:
http://springbyexample.org/
http://www.petrikainulainen.net/tutorials/
http://www.mkyong.com/tutorials/spring-tutorials/
Pro Spring 4th Edition
Spring Documentation (must read, but take your time to understand the concepts)
Now, to answer your questions, although a bit differently:
Is it possible to avoid using xml in Spring or better to mix xml files and annotations
Now a days, you would find Annotations a lot in Spring code available on net/SO along with XML configuration. However, you can certainly avoid XML if you wish.
Is it easy for Spring developers to work with Spring Boot?
Am I able to learn Spring using Spring Boot?
Is Spring Boot is mature enough to use it in production?
My personal opinion would be to go with Spring Boot only if you believe it offers you certain advantages which are not possible to achieve otherwise. Remember, you may save time now but later on, it would be an additional dependency in your app and you may need to understand its architecture to debug it if things go wrong OR to enhance it as per your app requirements. Better to have minimal dependencies, my learning till now :)

Spring Project without annotations in IntelliJ

I am using IntelliJ IDE which by default generates a annotation based SpringApplication when I create a new Project for Spring Application. I want to first learn the concepts of Spring Application without Annotations(XML based). Could anyone give me suggestion for how to set in the IDE such that I get a non-annotation based project by default when I select for New Project.
The current version of Spring is
3.2.0
I created a basic annotation based Spring 3.2.0 app here : https://github.com/ajorpheus/hello-spring/
If you are comfortable with Git/Github, then clone that repository locally and import that project into Intellij using File -> Import Project ( otherwise, you could download the zip of the project itself : https://github.com/ajorpheus/hello-spring/archive/master.zip and then go from there. No git-fu needed.)
This project runs fine in Intellij as a maven project.
I have taken the liberty of also interpreting your question as 'How to learn Spring'. IMHO, here is what helped me when I was starting out with Spring.
First Steps
To start with, for further reading or a bit of experimentation, these seem like a good start :
http://projects.spring.io/spring-framework/#quick-start
http://spring.io/guides/gs/maven/
Books / Resources
I also recall that reading 'Spring In Action - Third Edition' helped when I was starting out with Spring, though I would not recommend buying it now since a much more up-to-date Fourth Edition is on it's way.
A couple of threads here also cover the topic of 'Best Resources for learning Spring' :
Book suggestion for Spring framework
https://stackoverflow.com/questions/1610733/best-way-to-learn-spring-framework
You'll find some books/resources repeatedly being mentioned is threads such as the above. 'Spring Recipes', 'Spring in Action', 'Pro Spring', 'Official Spring Documentation' ... all of these 'spring' to mind :D.
Finally, as far as Spring is concerned, there is no dearth of resources or threads advising about these resources. I'd recommend not spending a lot of time researching where to start. Just a pick a book which has been mentioned in more than one threads and go for it !
Hope this helps !

How to configure Eclipse RCP with Spring

How can I configure eclipse RCP with spring? Do I need spring dm?
Can you please show me a tutorial on how to configure spring with Eclipse RCP or Eclipse RAP?
How can I add spring to Eclipse RCP and just use it? How can I see the context everywhere?
Do I have to add something to my Target Platform?
Is there any tutorial or can you please tell me more details?
I just want to use Spring with my Eclipse RCP application.
Using Spring DM is not the only way, but I believe it's the easiest and most complete/correct way of doing it. Prior to Spring DM, there were several projects with the goal of integrating Spring and Eclipse RCP, but none of them were very simple, or very Spring-like. I have come across a blogger who is currently writing a series of articles on integrating Spring and Eclipse RCP using Spring DM. The first 4 articles cover exactly what you need to know with examples (step 0 through step 3).
The entire list of articles is here:
http://angelozerr.wordpress.com/category/java/spring/spring-dm/
That same blogger talks about his own RCP/RAP project (where he is using Spring DM) in another set of articles. These are in French, but using Google Translate makes them useful for non-French speakers. Take a look at step 7 and step 8 here:
http://angelozerr.wordpress.com/about/dynaresume/
I recently wrote a blog about this topic, you can find step-by-step tutorial here: http://blog.novatec-gmbh.de/step-step-spring-eclipse-rcp-applications/
I think my answer might be helpful to anyone (like me) looking for building Spring DM, OSGI console application.
Although its been quite sometime Since Spring DM has been inherited as Gemini Blueprint, it is recommended to use Gemini Blueprint instead of Spring DM. Nevertheless, Spring DM is also a good starting point.
This tutorial is worth looking at: http://www.jroller.com/dbrosius/entry/osgi_spring_dm_w_o
It provides step by step information
NOTE: There is a small package-name typo in Manifest.MF file that needs to be fixed. Eclipse will flag it so it's a non-issue

Using Spring (3.0.5) in Eclipse (3.6 Helios)

I just got a book from Apress (Spring Recipes), and I started to learn the Spring framework and now I have a problem. I followed the steps in the book to add the Spring .jar-s to the build path. Everything seems to work fine, but the code I have just doesn't work.
My question is that: do you know about a good tutorial for integrating Spring with Eclipse? I googled for a while and I only found old tutorials (from 2007-2009) which just doesn't work with Eclipse 3.6.
use STS - Spring Tool Suite. It is built-upon Eclipse IDE. http://www.springsource.com/developer/sts
STS helps hugely (you can get it from the Eclipse Marketplace for free). The features of it I particularly like? Here's a few:
As a user of XML-based configuration I love having the bean graph visualized – it's great for reports – but the content assist when filling out bean properties is invaluable, both for names and for values (i.e., it makes writing that much XML not suck too much). I imagine that if you're heavily using autowiring or Java configuration it's less useful.
Refactoring support is also good (these days; it used to have bad bugs so you want to be patched up to date) and I've found that the pointcut search to be the only way to write a complex aspect without lots of round-trip testing.
But not all of STS is perfect. In particular, some of the content assist modes don't (seem to) help (me) that much, and it really only works well if you have your properties defined using public setters. Still, it helps a lot…
Apart from using STS as suggested, you can use spring and eclipse without any integration. There isn't that much an IDE integration can offer anyway (apart from autocompletion in the xml, and linking the xml to classes (inclding aop))

How to create reusable components in Spring MVC 3.0

Ok I really don't know where to start. I have been trying to develop reusable component-like pages in Spring MVC. I ended up using tiles. I had the idea from "Spring in action" book on writing ComponentControllerSupport class. But the problem starts with tile2 and spring 3.0. All old features of tile1 is deprecated and tile2 has changed a lot(like "page" attribute changed into "template" and "controllerClass" changed into "preparer" etc). If anybody knows how to write that "preparer" class or other ways to approach such reusable components please help me.
Do you know Spring Roo ? It generates a skeleton of application using best practices that should be good starting point for further development. See http://www.springsource.org/roo/why

Categories