menembus batas impian


This is a step-by-step guide on how to develop a Spring Framework MVC application from scratch using NetBeans. Spring is basically a technology committed to enabling you to build applications using Plain Old Java Objects (POJOs). It enables you to develop components as POJOs containing only our business logic, while the framework takes care of the many value adds you need to build enterprise applications — even in areas that you may not have considered when initially authoring the application. This objective requires a complicated framework, which conceals much difficulty from the developer. Because your business logic is abstracted from infrastructure concerns, it’s also likely to enjoy a longer existence, improving the return on investment of writing it. Business logic should change at the pace of your business; only if it is abstracted from infrastructure concerns can the impact on your code base of expected infrastructure change (such as selecting the application server) be reduced.
2)This tutorial uses the traditional XML style for configuration.

Prerequisite software:

Java SDK 1.5/1.6
NetBeans 5.0 and above
Spring Framework 2.0

For Creating Web application project using NetBeans, please do the follwoing steps:

1. Choose File > New Project (Ctrl-Shift-N) from the main menu. Under Categories select Java Web (If you are using NetBeans 6.0 or 6.1, select Web); under Projects select Web Application. Click Next.

2. In Project Name, enter SpringDemo. From the Server drop-down list, select the server you plan to work with. Leave all other settings at their defaults and click Next.

3. Select a Spring framework 2.5 checkbox. When you reach the final panel of the wizard, click Finish.

3)Download Spring Framework 2.5.1
(optional step if you are not having Netbeans 6 and above version installed in you system)

Visit the Spring official website at
To download the Spring Frame work click on “Download” link.
Then select “” link. This download contains all the dependencies required to run the spring framework.
Save the downloaded file onto your favorite directory.
Now extract the downloaded file ( into your favorite directory.
The dist directory of the spring framework contains the spring modules (modules directory) library files. We are mostly concern with these jar files. We will copy these jar files later into our development environment. These jar files are:


4)Configure web.xml

Go to the ‘springdemo/WEB-INF’ directory. Modify the minimal ‘web.xml’ file to suit our needs. We define a DispatcherServlet that is going to control where all our request are routed based on information we will enter at a later point. It also has a standard servlet-mapping entry that maps to the url patterns that we will be using. Let any url with an ‘.htm’ extension be routed to the ‘springdemo’ dispatcher.






Next, create a file called ‘springdemo-servlet.xml’ in the springdemo/WEB-INF directory. This is the file where definitions used by the DispatcherServlet should be entered. It is named based on the servlet-name from web.xml with ‘-servlet’ appended. This is a standard naming convention used in the Spring Framework.

5)Copy jars to “WEB-INF/lib”

Then, from the Spring distribution, copy spring.jar (spring-framework-2.5.1/dist/spring.jar) to the new WEB-INF/lib directory. Also copy commons-logging jars to the WEB-INF/lib directory (spring-framework-2.5.1/lib/jakarta-commons/commons-logging.jar). These jars will be deployed to the server and they are also used during the build process.
6)Configuration of database

Download “hibernate 3.0” jar from and add the jar to the WEB-INF/lib directory. Add “mysql-connector-java-5.0.3-bin” to the WEB-INF/lib directory. (optional step if you are not having Netbeans 6 and above version installed in you system)
7)Create database and tables in MySQL

Create database by name “springdemo”.

Create a table by name “user” under “springdemo” database.

“user” table consists of the following fields:

USER_ID integer
FIRST_NAME varchar(45)
LAST_NAME varchar(45)
COMPANY varchar(45)
COMMENTS varchar(200)

Since we are using hibernate we have to create a OR mapping file. The mapping file for “user” is created as an xml file by name “User.hbm” under com.simpleweb.user.bean directory under Source Packages directory.


<?xml version=”1.0″?> <!DOCTYPE hibernate-mapping PUBLIC “-//Hibernate/Hibernate Mapping DTD 2.0//EN” “”&gt; <hibernate-mapping> <class name=”com.simpleweb.user.bean.User” table=”user” lazy=”false” > <id name=”userId” column=”USER_ID” type=”java.lang.Integer”> <generator/> </id> <property name=”firstName” column=”FIRST_NAME” type=”java.lang.String” /> <property name=”lastName” column=”LAST_NAME” type=”java.lang.String” /> <property name=”company” column=”COMPANY” type=”java.lang.String” /> <property name=”comments” column=”COMMENTS” type=”java.lang.String” /> </class> </hibernate-mapping>

Configure database configurations by adding the following code in “springdemo-servlet.xml”


<!-- DataSource Property -->
<bean id="userDataSource">
	 <property name="driverClassName"><value>com.mysql.jdbc.Driver</value>
	 </property><property name="url"><value>jdbc:mysql:///springdemo</value>
	 </property><property name="username"><value>root</value></property>
	 <property name="password"><value>mysql</value></property>

 <!-- Database Property -->
<bean id="userHibernateProperties">
	 <property name="properties">
			 <prop key="">update</prop>
			 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.query.substitutions">true 'T', false 'F'</prop>
			 <prop key="hibernate.show_sql">true</prop>
			 <prop key="hibernate.c3p0.minPoolSize">5</prop>
			 <prop key="hibernate.c3p0.maxPoolSize">20</prop>
			 <prop key="hibernate.c3p0.timeout">600</prop>
			 <prop key="hibernate.c3p0.max_statement">50</prop>
			 <prop key="hibernate.c3p0.testConnectionOnCheckout">false</prop>

   <!-- Hibernate SessionFactory -->
<bean id="userSessionFactory">
	 <property name="dataSource"><ref local="userDataSource"/></property>
	 <property name="hibernateProperties"><ref bean="userHibernateProperties" /></property>

	 <!--  OR mapping files. -->
	 <property name="mappingResources">

Copy paste :


Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:


You are commenting using your account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )


Connecting to %s

%d blogger menyukai ini: