Spring MVC Step-by-Step Tutorial ported on NetBeans/GlassFish

I was recently using the 1.1 release of Craig MacKay’s Spring Module for NetBeans which supports the latest Spring Framework 2.5. Spring Framework tutorial hosted at NetBeans.org provides details on how to use this module in NetBeans IDE. Thomas Risberg’s Developing a Spring Framework MVC Application Step-by-Step tutorial is a good one which explains end-to-end web application development using Spring Framework 2.5. The sample in this tutorial was developed using Eclipse 3.3 and the application was deployed to Apache Tomcat 6.0.14. Spring supports JEE technologies, this sample application should run on any JEE compatible servers without much porting effort. I was able to run this tutorial using NetBeans IDE 6.0 and GlassFish V2 UR1 without any hassle. In fact, this combination worked out great for me with Craig MacKay’s plugin. A very useful plugin for Spring development on NetBeans IDE. I modified the original tutorial to use NetBeans and GlassFish infrastructure, and these tools should definitely help increase the productivity for Spring developers.

You can access the tutorial “Developing a Spring Framework MVC application step-by-step using NetBeans and GlassFish” here.

[Update: 11/09/09 – NetBeans wiki is missing the tutorial page since their recent migration to the new NetBeans.org infrastructure. I have removed the original redirect to the NB wiki, so you could access the tutorial directly from my website. The project can be downloaded from here].

27 thoughts on “Spring MVC Step-by-Step Tutorial ported on NetBeans/GlassFish

  1. Hello,

    thanks a lot for this tutorial.

    BTW: I can’t deploy the project at “4.6. Adding a form controller”. In your example of ‘springapp-servlet.xml’ I have to change each occurrence of ‘springgfapp’ to ‘springapp’ to make it work.

    bye ;O)
    michael

    Like

  2. hello,

    It seems the path for the tutorial “Developing a Spring Framework MVC Application Step-by-Step” has been changed. Could anyone please provide the updated path for this link.

    Thanks

    Like

  3. I am currently doing the tutorial. Thank you very much for this tutorial.
    I am stuck in the part 5.5 of the tutorial. Instead of using hsqldb, i am using mysql (it should not make a difference).

    when i running the test i am getting the following error:
    22/08/2008 10:47:57 org.springframework.test.AbstractSingleSpringContextTests loadContextLocations
    INFO: Loading context for locations: classpath:test-context.xml
    22/08/2008 10:47:57 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [test-context.xml]
    22/08/2008 10:47:57 org.springframework.test.AbstractSingleSpringContextTests loadContextLocations
    INFO: Loading context for locations: classpath:test-context.xml
    22/08/2008 10:47:57 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [test-context.xml]

    it does not seem to find where the classpath:text-context.xml is located.

    Any suggestions will be greatly appreciated.

    thanks

    Like

  4. Did you create the test-context.xml as mentioned in section 5.5?

    By looking at your logs, it seems Spring has loaded test-context.xml successfully from the classpath. Did you modify the jdbc.properties matching MySQL driver info?

    Are you getting any specific errors?

    -Arul

    Like

  5. thanks Arul for your reply.
    i have included the test-context.xml.

    instead of using jdbc.properties, i have hard-coded the values in the the xml file
    eg

    and commented out the propertyConfigurer.(hope it is ok to do that).

    So i got the error that i mentioned in my earlier post.

    I changed the getConfigLocations() in the JdbcProductDaotests.java from “classpath:test-context.xml”

    to

    protected String[] getConfigLocations() {
    return new String[] {“springapp/test/test-context.xml”}; }

    i got a new set of error:

    INFO: Loading XML bean definitions from class path resource [springapp/test/test-context.xml]
    25/08/2008 14:48:52 org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.GenericApplicationContext@3570b0: display name [org.springframework.context.support.GenericApplicationContext@3570b0]; startup date [Mon Aug 25 14:48:52 GMT+10:00 2008]; root of context hierarchy
    25/08/2008 14:48:52 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
    INFO: Bean factory for application context [org.springframework.context.support.GenericApplicationContext@3570b0]: org.springframework.beans.factory.support.DefaultListableBeanFactory@cfec48
    25/08/2008 14:48:53 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@cfec48: defining beans [productDao,dataSource,transactionManager]; root of factory hierarchy
    PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property ‘driverClassName’ threw exception; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not load JDBC driver class [com.mysql.jdbc.Driver]; nested exception is java.lang.ClassNotFoundException: com.mysql.jdbc.Driver)
    25/08/2008 14:48:53 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
    INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@cfec48: defining beans [productDao,dataSource,transactionManager]; root of factory hierarchy

    thanks

    Like

  6. i still can’t get the datasource bean to be displayed in the post so the values are:

    driverClassName –> com.mysql.jdbc.Driver
    url –> jdbc:mysql://localhost:3307/springwebapp
    username –> root
    password –> admin

    so i have hardcoded the values in the test-context.xml rather than use jdbc.properties

    thanks

    Like

  7. Hi Arul,
    i have finally fixed the problem. Forgot to add the mysql-connector jar file to the library.

    I got the whole tutorial running.

    thank you very much for the tutorial

    cheers

    🙂

    Like

  8. Hi Arul,

    I am trying to use hibernate to access the database rather than JDBC. I am using Netbeans 6.5 so i have created a hibernate.cfg.xml that lists all my database properties.
    i have also created a HibernateUtil.java for my sessionfactory.

    i do not know how to wire it in my xml files. Please advice.

    Also do you know of any spring mvc hibernate tutorials (hopefully in netbeans) that i can do?

    thanks

    Like

  9. Your best shot would be to look at the PetClinic sample bundled with Spring 2.5.5. It demonstrates data access strategies such as JDBC, Hibernate and JPA.

    Let me know if you have any specific questions.

    -Arul

    Like

  10. Thank you very much for your version of Spring tutorial!
    I found it on NetBeans Wiki and it is really work – regardless transfer all steps to Eclipse and MYSQL.
    I am absolutely newbie in this field – much more even my experience in Java is only 2 week long. And English is not my native language (please, sorry for mistakes).
    But I was so impressed of your easy and teachable manner that now I am going to look for your other articles and tutorials.
    Thank you, thank you, thank you.

    Like

  11. Is there anywhere I can find a tutorial on how to use the annotations features for spring 2.5 – all I can find is incomplete information.

    Like

  12. Hi, I’m using Netbeans 6.8 but am sure it doesn’t matter in the problem i’m having.(unless the libraries bundled in the netbeans distribution are wrong)

    the problem is, in the priceincrease form that gets into the browser, when i view the src, the from action is pointing to

    /springapp/WEB-INF/jsp/priceincrease.jsp which am sure will not be served as WEB-INF is blocked by the servlet container.

    Do you know what can be causing this.

    Kind regards

    Like

  13. hi all.i need help. previous 3 parts worked for me.but part four gives me errors

    i downloaded spring-form.tld from web somewhere becouse i can’t find it in spring freamework…
    i am using ECLIPSE Java EE IDE for Web Developers.
    Build id: 20090920-1017

    i’ve downloaded spring framework 23.0.2 release thanks for help in advance
    Josip

    img96.imageshack.us/i/29718014.jpg/

    img443.imageshack.us/i/90149143.jpg/

    img3.imageshack.us/i/62016171.jpg/

    img707.imageshack.us/i/11890248.jpg/

    Like

  14. Hi everyone new to this. I got stuck at 4.6. When i hit the execute then it takes me to /WEB-INF/jsp/priceicrease.jsp
    I’m using netbeans 6.5.1.
    Thanks for any help.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s