Struts + Spring + Hibernate integration example
In this tutorials, you will learn how to create a simple customer management (add and select) web application, Maven as project management tool, Struts 1.x as web framework, Spring as dependency injection framework and Hibernate as database ORM framework.
The overall integration architecture is look like following :
Struts (Web page) <---> Spring DI <--> Hibernate (DAO) <---> Database
To integrate all those technologies together, you should..
- Integrate Spring with Hibernate with Spring’s “LocalSessionFactoryBean” class.
- Integrate Spring with Struts via Spring’s ready make Struts plug-in – “ContextLoaderPlugIn“.
1. Project Structure
This is this final project structure.


2. Table script
Create a customer table to store the customer details.
DROP TABLE IF EXISTS `mkyong`.`customer`; CREATE TABLE `mkyong`.`customer` ( `CUSTOMER_ID` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, `NAME` VARCHAR(45) NOT NULL, `ADDRESS` VARCHAR(255) NOT NULL, `CREATED_DATE` datetime NOT NULL, PRIMARY KEY (`CUSTOMER_ID`) ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
3. Maven details
Define all the Struts, Spring and Hibernate dependency libraries in pom.xml.
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mkyong.common</groupId> <artifactId>StrutsSpringExample</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>StrutsExample Maven Webapp</name> <url>http://maven.apache.org</url> <repositories> <repository> <id>Java.Net</id> <url>http://download.java.net/maven/2/</url> </repository> <repository> <id>JBoss repository</id> <url>http://repository.jboss.com/maven2/</url> </repository> </repositories> <dependencies> <!-- Spring framework --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.5.6</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>2.5.6</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-struts</artifactId> <version>2.0.8</version> </dependency> <!-- J2EE library --> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> </dependency> <!-- Unit Test --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- Struts 1.3 framework --> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts-core</artifactId> <version>1.3.10</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts-taglib</artifactId> <version>1.3.10</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts-extras</artifactId> <version>1.3.10</version> </dependency> <!-- MySQL database driver --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.9</version> </dependency> <!-- Hibernate core --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> <version>3.2.7.ga</version> </dependency> <!-- Hibernate core library dependecy start --> <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.2.1</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.2</version> </dependency> <!-- Hibernate core library dependecy end --> <!-- Hibernate query library dependecy start --> <dependency> <groupId>antlr</groupId> <artifactId>antlr</artifactId> <version>2.7.7</version> </dependency> <!-- Hibernate query library dependecy end --> </dependencies> <build> <finalName>StrutsExample</finalName> </build> </project>
4. Hibernate
Nothing much need to configure in Hibernate, just declare a customer XML mapping file and model.
Customer.hbm.xml
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.mkyong.customer.model.Customer" table="customer" catalog="mkyong"> <id name="customerId" type="long"> <column name="CUSTOMER_ID" /> <generator class="identity" /> </id> <property name="name" type="string"> <column name="NAME" length="45" not-null="true" /> </property> <property name="address" type="string"> <column name="ADDRESS" not-null="true" /> </property> <property name="createdDate" type="timestamp"> <column name="CREATED_DATE" length="19" not-null="true" /> </property> </class> </hibernate-mapping>
Customer.java
package com.mkyong.customer.model; import java.util.Date; public class Customer implements java.io.Serializable { private long customerId; private String name; private String address; private Date createdDate; //getter and setter methods }
5. Spring
Spring’s beans declaration for Business Object (BO) and Data Access Object (DAO). The DAO class (CustomerDaoImpl.java) is extends Spring’s “HibernateDaoSupport” class to access the Hibernate function easily.
CustomerBean.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="customerBo" class="com.mkyong.customer.bo.impl.CustomerBoImpl" > <property name="customerDao" ref="customerDao" /> </bean> <bean id="customerDao" class="com.mkyong.customer.dao.impl.CustomerDaoImpl" > <property name="sessionFactory" ref="sessionFactory"></property> </bean> </beans>
CustomerBo.java
package com.mkyong.customer.bo; import java.util.List; import com.mkyong.customer.model.Customer; public interface CustomerBo{ void addCustomer(Customer customer); List<Customer> findAllCustomer(); }
CustomerBoImpl.java
package com.mkyong.customer.bo.impl; import java.util.List; import com.mkyong.customer.bo.CustomerBo; import com.mkyong.customer.dao.CustomerDao; import com.mkyong.customer.model.Customer; public class CustomerBoImpl implements CustomerBo{ CustomerDao customerDao; public void setCustomerDao(CustomerDao customerDao) { this.customerDao = customerDao; } public void addCustomer(Customer customer){ customerDao.addCustomer(customer); } public List<Customer> findAllCustomer(){ return customerDao.findAllCustomer(); } }
CustomerDao.java
package com.mkyong.customer.dao; import java.util.List; import com.mkyong.customer.model.Customer; public interface CustomerDao{ void addCustomer(Customer customer); List<Customer> findAllCustomer(); }
CustomerDaoImpl.java
package com.mkyong.customer.dao.impl; import java.util.Date; import java.util.List; import com.mkyong.customer.dao.CustomerDao; import com.mkyong.customer.model.Customer; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; public class CustomerDaoImpl extends HibernateDaoSupport implements CustomerDao{ public void addCustomer(Customer customer){ customer.setCreatedDate(new Date()); getHibernateTemplate().save(customer); } public List<Customer> findAllCustomer(){ return getHibernateTemplate().find("from Customer"); } }
6. Spring + Hibernate
Declare the database details and integrate Spring and Hibernate together via “LocalSessionFactoryBean“.
database.properties
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/mkyong jdbc.username=root jdbc.password=password
DataSource.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>WEB-INF/classes/config/database/properties/database.properties</value> </property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> </beans>
HibernateSessionFactory.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <!-- Hibernate session factory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource"/> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="mappingResources"> <list> <value>com/mkyong/customer/hibernate/Customer.hbm.xml</value> </list> </property> </bean> </beans>
SpringBeans.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <!-- Database Configuration --> <import resource="config/database/spring/DataSource.xml"/> <import resource="config/database/spring/HibernateSessionFactory.xml"/> <!-- Beans Declaration --> <import resource="com/mkyong/customer/spring/CustomerBean.xml"/> </beans>
7. Struts + Spring
To integrate Spring with Struts, you need to registering a Spring’s build-in Struts plug-in “ContextLoaderPlugIn” in struts-config.xml file. In Action class, it have to extends the Spring’s “ActionSupport” class, and you can get the Spring bean via getWebApplicationContext().
AddCustomerAction.java
package com.mkyong.customer.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.beanutils.BeanUtils; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.springframework.web.struts.ActionSupport; import com.mkyong.customer.bo.CustomerBo; import com.mkyong.customer.form.CustomerForm; import com.mkyong.customer.model.Customer; public class AddCustomerAction extends ActionSupport{ public ActionForward execute(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception { CustomerBo customerBo = (CustomerBo) getWebApplicationContext().getBean("customerBo"); CustomerForm customerForm = (CustomerForm)form; Customer customer = new Customer(); //copy customerform to model BeanUtils.copyProperties(customer, customerForm); //save it customerBo.addCustomer(customer); return mapping.findForward("success"); } }
ListCustomerAction.java
package com.mkyong.customer.action; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; import org.springframework.web.struts.ActionSupport; import com.mkyong.customer.bo.CustomerBo; import com.mkyong.customer.model.Customer; public class ListCustomerAction extends ActionSupport{ public ActionForward execute(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception { CustomerBo customerBo = (CustomerBo) getWebApplicationContext().getBean("customerBo"); DynaActionForm dynaCustomerListForm = (DynaActionForm)form; List<Customer> list = customerBo.findAllCustomer(); dynaCustomerListForm.set("customerList", list); return mapping.findForward("success"); } }
CustomerForm.java
package com.mkyong.customer.form; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; public class CustomerForm extends ActionForm { private String name; private String address; //getter and setter, basic validation }
Customer.properties
#customer module label message customer.label.name = Name customer.label.address = Address customer.label.button.submit = Submit customer.label.button.reset = Reset #customer module error message customer.err.name.required = Name is required customer.err.address.required = Address is required
add_customer.jsp
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<html>
<head>
</head>
<body>
<h1>Struts + Spring + Hibernate example</h1>
<h2>Add Customer</h2>
<div style="color:red">
<html:errors/>
</div>
<html:form action="/AddCustomer.do">
<div style="padding:16px">
<div style="float:left;width:100px;">
<bean:message key="customer.label.name" /> :
</div>
<html:text property="name" size="40" maxlength="20"/>
</div>
<div style="padding:16px">
<div style="float:left;width:100px;">
<bean:message key="customer.label.address" /> :
</div>
<html:textarea property="address" cols="50" rows="10"/>
</div>
<div style="padding:16px">
<div style="float:left;padding-right:8px;">
<html:submit>
<bean:message key="customer.label.button.submit" />
</html:submit>
</div>
<html:reset>
<bean:message key="customer.label.button.reset" />
</html:reset>
</div>
</html:form>
</body>
</html>list_customer.jsp
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%> <html> <head> </head> <body> <h1>Struts + Spring + Hibernate example</h1> <h2>List All Customers</h2> <table border="1"> <tr><td>Customer Name</td><td>Address</td></tr> <logic:iterate id="customer" name="dynaCustomerListForm" property="customerList"> <tr> <td><bean:write name="customer" property="name"/></td> <td><bean:write name="customer" property="address"/></td> </tr> </logic:iterate> </table> <br/> <br/> <html:link action="/AddCustomerPage.do">Add Customer</html:link> </body> </html>
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans> <form-bean name="customerForm" type="com.mkyong.customer.form.CustomerForm" /> <form-bean name="dynaCustomerListForm" type="org.apache.struts.action.DynaActionForm"> <form-property name="customerList" type="java.util.List"/> </form-bean> </form-beans> <action-mappings> <action path="/AddCustomerPage" type="org.apache.struts.actions.ForwardAction" parameter="/pages/customer/add_customer.jsp"/> <action path="/AddCustomer" type="com.mkyong.customer.action.AddCustomerAction" name="customerForm" validate="true" input="/pages/customer/add_customer.jsp" > <forward name="success" redirect="true" path="/ListCustomer.do"/> </action> <action path="/ListCustomer" type="com.mkyong.customer.action.ListCustomerAction" name="dynaCustomerListForm" > <forward name="success" path="/pages/customer/list_customer.jsp"/> </action> </action-mappings> <message-resources parameter="com.mkyong.customer.properties.Customer" /> <!-- Spring Struts plugin --> <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="/WEB-INF/classes/SpringBeans.xml" /> </plug-in> </struts-config>
web.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Struts Hibernate Examples</display-name> <servlet> <servlet-name>action</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class> <init-param> <param-name>config</param-name> <param-value> /WEB-INF/struts-config.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app>
8. Demonstration
1. List customer page
List all customers from database.
http://localhost:8080/StrutsSpringExample/ListCustomer.do

2. Add customer page
Add customer detail into database.
http://localhost:8080/StrutsSpringExample/AddCustomerPage.do


You website is really very good.
Hi meenu,
Your communication is very poor ….. Pls dont kill the people
Mallikarjun
Its really useful.
I have struck in some place i am getting exception while starting tomcat
Apr 16, 2013 7:34:55 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Apr 16, 2013 7:34:55 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/StrutsSpringExample] startup failed due to previous errors
how to create project structure in eclipse please help me
All your tutorials are very easy and helpful. Thank you and keep up the good work!
Thank you for articel.This working if I change pom.xml
- remove javaee-api 6.0
- add servlet-api 2.5.0
- add asm 3.1
Mkyong,
Thank you very much for being so kind. Its an excellent tutorial. Dont be discouraged by some complaints here. Actually the whole idea of Spring Integration is matured and in evolving nature. A newbie to Java cant get it straight away working. I have tried to delpoy this app. in MyEclipse. Lot of learning. Yes there are several issues, like asm.jar etc. But then in the end you see INTEGRATION that is enterprise-wide.
Thank you very much, once again.
Thanks for your kind comment, I’m planing to upgrade the whole series of Spring tutorials soon, hope it getting better and clear :)
Sir ,
i need validation for this application with detailed explanation….
I got following error message during deployment.
Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: javax.servlet.UnavailableException. Please see server.log for more details.
I am running it on Netbeans. How to fix this pblm.
Regards
Just to inform, I am running on Netbeans using GlassFish server. I don’t have tomcat installed. Pls help me as i want to include this example in my project.
Thanks
Hi thanks for the tutorial.
I was able to get this working along with the spring security tutorial.
Can you please let me know how to configure connection pool with this in a tomcat env.
Thanks,
Sidd
i am getting the error
Stacktraces
There is no Action mapped for namespace / and action name . – [unknown location]
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:619)
I am trying to understand this project .Hope this all works.My questions are why do i have to write the CUSTOMER BEAN where does this help?Why do i have to create the customerBo where this help and why do i have to create the customerDao it’s the same with customerBo.
Why is this happenig?
Complete waste of time like all the others your code is not working Right. If i have to spend 20 Hours in something that after i have read it i have to spend other 20 hours to debug it IT IS COMPLETE WASTE OF TIME .
May I know “what” is not working? Please post your last error caused by.
P.S All examples I posted are well tested at my working environment.
Can you show me how is the code in UpdateCustomerAction.java and DeleteCustomerAction.java look like?
Thanks!
hi furyfish,
there is noclass file named UpdateCustomerAction.java and DeleteCustomerAction.java in this project. the problem i am getting is in AddCustomerAction class and ListCustomerAction class.
hi mykyong,
i am using netbeans ide7.1.2 and tomcat version 6.0.35. i wish to run this project in tomcat server. i include your project in my ide without any problem. i can create war file too.. while running this project via tomcat, showing some errors, i am attaching my log file contents with this. please go through that and give me proper guidance.
asm library conflict issue, try upgrade or downgrade your asm.jar.
hi mkyong,
i found a new issue now. i cant build my project from command prompt. it showing the error message build failure. i am using apache-maven-2.2.1 and jdk1.6.0_31. i am attaching the error log. please go through it and replay asap.
[INFO] ————————————————————————
[ERROR] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Compilation failure
E:\ARAVIND SANKARAN\StrutsSpringExample\src\main\java\com\mkyong\customer\dao\Cu
stomerDao.java:[11,5] generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
List findAllCustomer();
E:\ARAVIND SANKARAN\StrutsSpringExample\src\main\java\com\mkyong\customer\form\C
ustomerForm.java:[31,2] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
@Override
E:\ARAVIND SANKARAN\StrutsSpringExample\src\main\java\com\mkyong\customer\bo\imp
l\CustomerBoImpl.java:[23,12] generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
public List findAllCustomer(){
E:\ARAVIND SANKARAN\StrutsSpringExample\src\main\java\com\mkyong\customer\bo\Cus
tomerBo.java:[11,5] generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
List findAllCustomer();
E:\ARAVIND SANKARAN\StrutsSpringExample\src\main\java\com\mkyong\customer\action
\ListCustomerAction.java:[28,6] generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
List list = customerBo.findAllCustomer();
E:\ARAVIND SANKARAN\StrutsSpringExample\src\main\java\com\mkyong\customer\dao\im
pl\CustomerDaoImpl.java:[19,12] generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
public List findAllCustomer(){
[INFO] ————————————————————————
[INFO] For more information, run Maven with the -e switch
[INFO] ————————————————————————
[INFO] Total time: 9 seconds
[INFO] Finished at: Fri Oct 05 13:16:24 IST 2012
[INFO] Final Memory: 10M/25M
[INFO] ————————————————————————
E:\ARAVIND SANKARAN\StrutsSpringExample>
i got 404 error , when i run this program..
i got 404 error to run this program…
i got 404 error ,
when i download ur project and run it,
http://localhost:4888//AddCustomerPage.do
nice clean tutorial
Dear Mkyong,
I am new to Spring.
can u tell me in the following code from where container will get property name “sessionFactory” as there is no property named “sessionFactory” present in com.mkyong.customer.dao.impl.CustomerDaoImpl class.
Thanks in advance for your support.
Ranjit
hi,
I downloaded your project and added it to tomcat server,but when i started the tomcat it gives me a exception below:
SEVERE: Servlet /StrutsSpringExample threw load() exception
java.lang.ClassNotFoundException: org.apache.commons.beanutils.Converter
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2404)
at java.lang.Class.getConstructor0(Class.java:2714)
at java.lang.Class.newInstance0(Class.java:343)
at java.lang.Class.newInstance(Class.java:325)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1149)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Hi All,
I have tried follow all the suggested ways here in order to get rid of the error
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(I)V
at net.sf.cglib.core.DebuggingClassWriter.(DebuggingClassWriter.java:47)
at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)
but failed completely. Have made the following changes to the original pom.xml
ADDED
MODIFIED
Could there be any one having an idea on how i can get the example up and running ?
hi mkyong… i have imported your jar to the eclipse as a project. but when i am hitting the server with the link http://localhost:8080/StrutsSpringExample/AddCustomerPage.do. then i am getting the 404 error. i think application is not able to map the url with the jsp page add_customer.jsp. any help from you will be very much appreciated. because its first time i am using struts spring and hibernate.
Hi Mkyong,
Nice article. Thanks for posting.
I am using Oracle and Weblogic 10.x server.
What should I change if I want to use JDBC/JNDI instead as I have DS setup in my weblogic?
I have changed datasource.xml as below but it seems I am missing something or doing something wrong.
Can you provide the datasource.xml?
Thanks
I download your project. Complile with Maven and deploy to Tomcat. Even the project using asm-3.1.jar, I am still get the same exception below.
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(I)V
at net.sf.cglib.core.DebuggingClassWriter.(DebuggingClassWriter.java:47)
at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:116)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.cglib.proxy.Enhancer.(Enhancer.java:69)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:117)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:188)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.(AbstractEntityTuplizer.java:128)
at org.hibernate.tuple.entity.PojoEntityTuplizer.(PojoEntityTuplizer.java:78)
Thanks ! Very helpful content.
hi sir,
i can not able to run this project on myeclipse plz help me sir plz
i m using ms sql server and tomcate5.5
myeclipse having in build maven tool.so plz tel me how to configure all it and
how to run project
Hi its very useful.. can you please give me the Jar files required to run this project.
becoz i am getting the following problems while configuring.
Unbound classpath variable: ‘M2_REPO/antlr/antlr/2.7.7/antlr-2.7.7.jar’ in project StrutsSpringExample
like the above error i am getting around 33 errors. i think this problem is becoz of jar files missing in the class path. can you please upload all the required jar files or give me the link to download.
thanks in advance.
Very good material. Easy to understand
Hello
I am new to this hybernate. Will you please send me the coding for MVC to me.. Then I will get some idea in hybernate. Please send me in my mail.
Click on above download link for full example.
Hi,
I have tried this application in tomcat. But it’s not working. It’s giving the below error
Aug 24, 2011 8:11:45 PM org.apache.struts.action.ActionServlet handleConfigException
SEVERE: Parsing error processing resource path /WEB-INF/struts-config.xml
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
Please post your last caused by error message. Java error messages are in stack.
Hi,
I am getting error while running this application
“dynaCustomerListForm” not found in any scope.
any one can help me how to resolve this issue.please send the solution on my mail id (arbindnegi@gmail.com).
Thank you,
Hi,
excuse me, but did you have solve your problem?
Because I have the same error.
Thank you for your answer.
hi
did you have solve the problem pllz ..a have the same error pllz help mee
Hi ,
this is very usefull for us.. But if you give the list of jars or give the link to download the jars. it will be very usefull for the beginners.
thanks,
D.Rathakrishnan
Attached is Maven project. It will download the entire dependencies automatically.
I come from China , because of I am not good at english ,not often go to visit foreign web site , after I see this ,I should often come here , it is very good
You’re welcome, we all learn through process, my English is not good either :p
Mind to contact me via contact form? I plan to expand this site to Chinese version, may need some advices from you :)
it is very good ,i am so glad to help you, when I start to learn J2EE , the materiel is so much many ,most of materiel is translate from English ,but they are not complete . if you expand the site to Chinese version , I think the translation task is very large , but I believe that will have many Chinese university student visit it .
i am not able to deploy the project, tried on Tomcat, geeting error on tomcat server:
startup failed due to previous error:
Thanks a lot buddy for your post . It really helped me a lot. Had some issues initially but all resolved after reading your reply on queries.
It is Really helpful to understand the Spring Integration Concepts.
Yes asm-1.5.3.jar does the problem. You can solve it like this: to pom.xml add:
asm
asm
3.1
and after you did: mvn install go to target directory, enter to war and there delete old asm-1.5.3.jar. New asm-3.1.jar must stay there!
hmm it delete my code:
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.1</version>
</dependency>
For me this app is not working… I have configured everything as u said.. pls help.. error no:404 page not found…
404 means you access an URL which is doesn’t exists, you did configured something wrong, try download the attached example and compare with yours.
add this dependency to your pom.xml
asm
asm
3.1
Hibernate depends on asm
Well, this adding asm doesnt solve the 404 error. I have copied the exact thing did the same thing on my mac / as well as my fedora machine.. I was using Tomcat 7.
What am I missing?
Any idea ?
see log file or console, is there any error message during your application start up?
very good website and good thought,thanks for ur team
Hi,
Thanks lot. I appreciate your effort god bless U.
I believe you need asm.jar, thank you for tuto.
Just wanted to say thank you and appreciate your effort and zeal to share your knowledge with fellow developers. People like you make development easy. Keep it up.
Hi,
thanks a lot for this tutorial.
Simple but very effective.
thanks again.
Ajith
@shan
Obviously, java.io.FileNotFoundException….please verify your file location, btw, please build this project with Maven.
Dear,
Thanx for all you’v helped my a lot.
Dear,
i downloaded this example and deployed in tomcat…..
but am getting
HTTP Status 404 – Servlet action is not available
error…..
please mention do i need to make any aditional changes in struts-config
regards,
shan
404 is page not found. How you access it?
i imported the project in myeclipse ide and
run the maven command to package…..
packaged successfully the place that war file in tomcat webapp
when i type
http://localhost/StrutsExample/ListCustomer.do
then i got the error 404
zip your project, exclude the jar, send to my email for debug. During project initializing, any error message logged in your Tomcat log file?
SEVERE: Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [config/database/spring/DataSource.xml]
Offending resource: ServletContext resource [/WEB-INF/classes/SpringBeans.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/classes/config/database/spring/DataSource.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/classes/config/database/spring/DataSource.xml]
yes i sent my project zip and waiting your reply….
i have the same problem.. any suggestions?
me too, encounter that problem
solve it, put the StrutsExample.war file unser /webapps;
visit: http://localhost:8080/StrutsExample/AddCustomerPage.do
Could you advise about my error logs?
No idea about its ,I’m just beginner in spring and hibernate .
thank :)
org/hibernate/cfg/Configuration is belong to Hibernate library, just include it into your project classpath.
After I did from your suggestion. I found another something like below
Do you have any mentions for error log?
—————————————————————————————
Obviously…you do not have the Struts library, please include it in your project classpath. Btw, if you are not familiar with Maven, please use your prefer build tool or copy the dependency libraries manually.
hi mykyong. I have followed your instruction but i still have had a problem like this:
What’s this bug?
Please help me!
Thank in advanced!
you run the attached example and hits this error? It may due to some libraries conflict issues, impossible to blind guess here, would you mind to send me your project via email?
Hi Mykyong!
First of all, thanks for your quickly reply!
I downloaded the attached example and hits this error.
Additionally, i used maven to get some dependency librarys.
This is my projests which uploaded to mediarefire with link http://www.mediafire.com/?3yfiw3yznk4.
Regards!
Downloaded your project and do a quick test, hits
Your included library is using ‘asm-1.5.3.jar’, which is quite old and causing the issue, try upgrade to ‘asm-3.1.jar’.
In my attached project, it will download the ‘asm-3.1.jar’ automatically, wonder why you will get the old asm library? Is you include it manually?
Hi, i upgraded asm-1.5.3.jar to asm-3.1. But it has hit new bug like this:
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/classes/SpringBeans.xml]
Jun 15, 2010 4:41:35 AM org.springframework.web.struts.ContextLoaderPlugIn init
SEVERE: Context initialization failed
… [/WEB-INF/classes/SpringBeans.xml]; nested exception is java.io.FileNotFoundException:
Could not open ServletContext resource [/WEB-INF/classes/SpringBeans.xml]
I tried to fix ix in struts-config.xml but it sill hasn’t run.
“In my attached project, it will download the ‘asm-3.1.jar’ automatically, wonder why you will get the old asm library? Is you include it manually?”
I use maven to get all dependency jar files. After that, I copy all file to WEB-INF/lib folder. Have I do it in right way?
Obviously, the SpringBeans.xml is not found, resource folder problem. The attached example in this article should working fine, tested. Please compare with yours, or you can configure it easily
http://www.mkyong.com/maven/how-to-change-maven-resources-folder-location/
Let Maven handle the dependencies, no point to copy it manually. See below , in case you afraid the dependencies are not deploy correctly in Eclipse debugging environment.
http://www.mkyong.com/maven/maven-dependency-libraries-not-deploy-in-eclipse-ide/
Hi Mykyong,
I have downloaded your project example again. And it run.
In the project which I sent to you, I think that I added wrong dependency jars by hand.
In old project, i have done like below:
1.Rownload your project.
2.run mvn eclipse:eclipse command.
3.Run the project on tomcat 5.5 server, and it didn’t work.And in WEB-INF folder i added new subfolder name by lib and then, I copy some dependency jar files to that folder(lib). And then, I configure Java Build Path point to lib folder. And I think I had mistake in this step.
Instead of doing like step 3, I follwed your instruction link to change dependency libraries (http://www.mkyong.com/maven/maven-dependency-libraries-not-deploy-in-eclipse-ide/), after that I restart the workspace. And that’s great, It run.
-After running it and thinking about the bugs with SpringBean.xml? I have an question that what’s actually address of “/WEB-INF/classes/SpringBeans.xml”. And i found it in D:\SpringProject\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\StrutsSpringExample\WEB-INF\classes. It means that when we run the project in server it temporary deploy to a tmp folder in server.
And i found that why my old project could not run when manually added lib folder as I did.
–> the problem is that dependency lib directory different from SpringBeans.xml directory (Is it right,Mkyong?)
Anyway, thanks you alot, hope to see new your tutorial about j2ee.
Good to know it work to you.
Q : “the problem is that dependency lib directory different from SpringBeans.xml directory (Is it right,Mkyong?)”
A : Not really sure, since i do not have this problem, just make the XML file is exists in the Eclipse “org.eclipse.wst.server.core” plugin folder, it’s where the Eclipse run your project.
Hi
I am getting the same error
.. i had a look and found the i am using asm-1.5.3.jar.
As i am new to maven,can you please let me know how to replace it with asm-3.1.jar as i dont have explicit dependency mentioned in pom for this jar
Hi Vikas, have you installed maven. You can download it from here http://maven.apache.org/download.html.
After that try these steps below:
1.run mvn eclipse:eclipse command.
2.follow this instruction link to change dependency libraries (http://www.mkyong.com/maven/maven-dependency-libraries-not-deploy-in-eclipse-ide/),
3.after that restart the workspace
4.Run project.
Good luck!