Struts 2 + Spring + Hibernate integration example
In this tutorial, it shows the integration between “Struts2 + Spring + Hibernate“. Make sure you check the following tutorials before continue.
- Struts 2 + Hibernate integration example
- Struts 2 + Spring integration example
- Struts 1.x + Spring + Hibernate integration example
See the summary of integration steps :
- Get all the dependency libraries (a lot).
- Register Spring’s ContextLoaderListener to integrate Struts 2 and Spring.
- Use Spring’s LocalSessionFactoryBean to integrate Spring and Hibernate.
- Done, all connected.
See the relationship :
Struts 2 <-- (ContextLoaderListener) --> Spring <-- (LocalSessionFactoryBean) --> Hibernate
Tutorials Start…
It will going to create a customer page, with add customer and list customer function. Front end is using Struts 2 to display, Spring as the dependency injection engine, and Hibernate to doing the database operation. Let start…
1. Project structure
Project folder structure.


2. MySQL table script
Customer’s table script.
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=17 DEFAULT CHARSET=utf8;
3.Dependency libraries
This tutorials request many dependency libraries.
Struts 2…
<!-- Struts 2 --> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.1.8</version> </dependency> <!-- Struts 2 + Spring plugins --> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-spring-plugin</artifactId> <version>2.1.8</version> </dependency>
MySQL…
<!-- MySQL database driver --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.9</version> </dependency>
Spring…
<!-- 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>
Hibernate…
<!-- Hibernate core --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> <version>3.2.7.ga</version> </dependency> <!-- Hibernate core library dependency 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 dependency end --> <!-- Hibernate query library dependency start --> <dependency> <groupId>antlr</groupId> <artifactId>antlr</artifactId> <version>2.7.7</version> </dependency> <!-- Hibernate query library dependency end -->
4. Hibernate…
Only the model and mapping files are required, because Spring will handle the Hibernate configuration.
Customer.java – Create a class for customer table.
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 }
Customer.hbm.xml – Hibernate mapping file for customer.
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 20 Julai 2010 11:40:18 AM by Hibernate Tools 3.2.5.Beta --> <hibernate-mapping> <class name="com.mkyong.customer.model.Customer" table="customer" catalog="mkyong"> <id name="customerId" type="java.lang.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>
5. Struts 2…
Implements the Bo and DAO design pattern. All the Bo and DAO will be DI by Spring in the Spring bean configuration file. In the DAO, make it extends Spring’s HibernateDaoSupport to integrate Spring and Hibernate integration.
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> listCustomer(); }
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; //DI via Spring public void setCustomerDAO(CustomerDAO customerDAO) { this.customerDAO = customerDAO; } //call DAO to save customer public void addCustomer(Customer customer){ customerDAO.addCustomer(customer); } //call DAO to return customers public List<Customer> listCustomer(){ return customerDAO.listCustomer(); } }
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> listCustomer(); }
CustomerDAOImpl.java
package com.mkyong.customer.dao.impl; import java.util.List; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.mkyong.customer.dao.CustomerDAO; import com.mkyong.customer.model.Customer; public class CustomerDAOImpl extends HibernateDaoSupport implements CustomerDAO{ //add the customer public void addCustomer(Customer customer){ getHibernateTemplate().save(customer); } //return all the customers in list public List<Customer> listCustomer(){ return getHibernateTemplate().find("from Customer"); } }
CustomerAction.java – The Struts2 action is no longer need to extends the ActionSupport, Spring will handle it.
package com.mkyong.customer.action; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.mkyong.customer.bo.CustomerBo; import com.mkyong.customer.model.Customer; import com.opensymphony.xwork2.ModelDriven; public class CustomerAction implements ModelDriven{ Customer customer = new Customer(); List<Customer> customerList = new ArrayList<Customer>(); CustomerBo customerBo; //DI via Spring public void setCustomerBo(CustomerBo customerBo) { this.customerBo = customerBo; } public Object getModel() { return customer; } public List<Customer> getCustomerList() { return customerList; } public void setCustomerList(List<Customer> customerList) { this.customerList = customerList; } //save customer public String addCustomer() throws Exception{ //save it customer.setCreatedDate(new Date()); customerBo.addCustomer(customer); //reload the customer list customerList = null; customerList = customerBo.listCustomer(); return "success"; } //list all customers public String listCustomer() throws Exception{ customerList = customerBo.listCustomer(); return "success"; } }
6. Spring…
Almost all the configuration is done here, at all, Spring is specialized in integration work :).
CustomerBean.xml – Declare the Spring’s beans : Action, BO and DAO.
<?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="customerAction" class="com.mkyong.customer.action.CustomerAction"> <property name="customerBo" ref="customerBo" /> </bean> <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" /> </bean> </beans>
database.properties – Declare the database details.
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/mkyong jdbc.username=root jdbc.password=password
DataSource.xml – Create a datasource bean.
<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 – Create a sessionFactory bean to integrate Spring and Hibernate.
<?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 – Create a core Spring’s bean configuration file, act as the central bean management.
<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/spring/DataSource.xml"/> <import resource="config/spring/HibernateSessionFactory.xml"/> <!-- Beans Declaration --> <import resource="com/mkyong/customer/spring/CustomerBean.xml"/> </beans>
7. JSP page
JSP page to display the element with Struts 2 tags.
customer.jsp
<%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> </head> <body> <h1>Struts 2 + Spring + Hibernate integration example</h1> <h2>Add Customer</h2> <s:form action="addCustomerAction" > <s:textfield name="name" label="Name" value="" /> <s:textarea name="address" label="Address" value="" cols="50" rows="5" /> <s:submit /> </s:form> <h2>All Customers</h2> <s:if test="customerList.size() > 0"> <table border="1px" cellpadding="8px"> <tr> <th>Customer Id</th> <th>Name</th> <th>Address</th> <th>Created Date</th> </tr> <s:iterator value="customerList" status="userStatus"> <tr> <td><s:property value="customerId" /></td> <td><s:property value="name" /></td> <td><s:property value="address" /></td> <td><s:date name="createdDate" format="dd/MM/yyyy" /></td> </tr> </s:iterator> </table> </s:if> <br/> <br/> </body> </html>
8. struts.xml
Link it all ~
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <action name="addCustomerAction" class="customerAction" method="addCustomer" > <result name="success">pages/customer.jsp</result> </action> <action name="listCustomerAction" class="customerAction" method="listCustomer" > <result name="success">pages/customer.jsp</result> </action> </package> </struts>
9. Struts 2 + Spring
To integrate Struts 2 and Spring, just register the ContextLoaderListener listener class, define a “contextConfigLocation” parameter to ask Spring container to parse the “SpringBeans.xml” instead of the default “applicationContext.xml“.
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 2 Web Application</display-name> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/SpringBeans.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> </web-app>
10. Demo
Test it : http://localhost:8080/Struts2Example/listCustomerAction.action


Reference
- Struts 2 + Hibernate integration example
- Struts 2 + Spring integration example
- Struts 2 + Hibernate example with Full Hibernate Plugin
- Struts 1.x + Spring + Hibernate integration example







Hi,
Can You Please upload .war file
Thanks,
Hi MyKong……Could you please explain the folder structure.
Hi!!
i m trying to import without maven dependency ,but not working yet
from where i can get spring jars and spring 2.0 jar completable with this project
After setting up this project in eclipse, i am getting this error.
The requested resource (/Struts2Example/) is not available.
How does the server knows that it should access directly the pages/customer.jsp file without specifying in web.xml file?
Can you please solve this issue?
Hi
Thanks for the valuable post. I got worked the example by added required jars in web-inf lib folder without using maven. Once again thanks.
I have been working on this example and I have a question: imagine I don’t want to rewrite my old jsps to use struts tags, is it possible to use BOs or DAOs directly from a helper class? I tried it but initialization (injection?) does not happen and info cannot be retrieved from DB. I know it is not the best way but it is a temporary solution before rewritting JSPs…
BTW, very good tutorial and website!
Excellent and Simple article
You can certainly see your skills in the work you write. The world hopes for even more passionate writers such as you who aren’t afraid to mention how they believe. At all times go after your heart.
[...] 2 + Spring + Quartz scheduler integration example Example to integrate Spring + Struts 2 + Quartz.Struts 2 + Spring + Hibernate integration example Example to integrate Spring + Struts 2 + Hibernate.Spring FAQsInstall Spring IDE in Eclipse [...]
Hi,
When I run the program, I am getting the following error “Error configuring application listener of class org.springframework.web.context.ContextLoaderListener”. Kindly help me
Thanks a lot, your Example is excellent and Helped me a lot in making mine successful.
[...] Struts 2 + Spring + Hibernate integration example Integrate Struts 2, Spring and Hibernate framework. [...]
Excellent tutorial mate…….
but i m not able to save the oject when submit is clicked.
It says “project_name/addCustomerAction” not found……..
Any help …
plz…
Please help in which folder, we want to load jar files,
what which folder? Don’t get you
Sorry for late reply
I don’t know where and what are the jar file to be added to this project
Download above example, all dependencies are declared in pom.xml file.
thank you very much, can i create a new folder in web-inf as lib and save all related jar files there which is mentioned in pom.xml, am sorry sir am working in struts2 and am eager to learn spring, please help me.
after creating a lib folder in web-inf and saved all jar files there
now i get 2 errors 1 in web.xml as
——————————————————————
The content of element type “web-app” must match “(icon?,display-name?,description?,distributable?,context-
param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-file-
list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-constraint*,login-config?,security-role*,env-
entry*,ejb-ref*,ejb-local-ref*)”.
——————————————————————
2nd error in CustomerAction.java that implements ModelDriven
“ModelDriven cannot be resolved to a type”
Please help thanks a lot sir.
1st error message is because you declared some invalid settings in your web.xml, either sequence or syntax.
2nd error may caused by missing of library, you should learn Maven instead of manage the dependency library yourself.
Hi Saleem,
I am going through the same problem which you faced earlier. Please help. My skype id is amit.jain976.
Please add me on skype.
Thanks
Amit
Hi amit is working 5n… need clarification get me @ “saleem.hbs” [my skype id]
Other issues are cleared, when starting the tomcat server , it throws exception…..
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’ defined in ServletContext resource [/WEB-INF/classes/config/spring/HibernateSessionFactory.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
What’s your last caused by?
The java.lang.NoClassDefFoundError: javax/transaction/TransactionManager is belong to javaee.jar, if you are deployed on Tomcat, you need to get this from your J2EE SDK. For application server, it always comes with the javaee.jar.
Hi Mkyong,
Your Article (Struts 2 + Spring + Hibernate integration example)is good. Can you please let us know how to add validations in the Action class (then should we extend ActionSupport of Struts2? or do you suggest any other way?
Regards
Rao
For me, i just put all validation code inside the BO, after all BO is used to handle all the business logic, including the validation.
My applicationContext.xml file was broken in my previous posting.
Please help me to find the Exception.
Please pardon me if this is not a place to post this kind of problem.
Hi,
I am integrating hibernate 3.0 and spring 2.5.6, but I have the following Exception:
Exception in thread “main” org.springframework.orm.hibernate3.HibernateQueryException: unexpected token: ON near line 1, column 59 [FROM com.celerant.model.TbSkuLookup a INNER JOIN TbSkus b ON (b.skuId = a.skuId) INNER JOIN TbStyle c ON (c.styleId = b.styleId) ...........
applicationContext.xml:
net.sourceforge.jtds.jdbc.Driver
jdbc:jtds:sqlserver://localhost:1433/celerant
xxxxx
xxx
com/celerant/model/TbAttr1Entry.hbm.xml,
com/celerant/model/TbAttr2Entry.hbm.xml,
com/celerant/model/TbSizeEntry.hbm.xml,
com/celerant/model/TbSkuBucket.hbm.xml,
com/celerant/model/TbSkuLookup.hbm.xml,
com/celerant/model/TbSkus.hbm.xml,
com/celerant/model/TbStyle.hbm.xml
org.hibernate.dialect.SQLServerDialect
false
My MainTest.java:
package com.celerant.web;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.celerant.dao.PriceDaoImpl;
public class Main {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(“applicationContext.xml”);
String barcode = “10001801″;
PriceDaoImpl priceDaoImpl = (PriceDaoImpl)context.getBean(“priceDao”);
List data = priceDaoImpl.getPriceCheckResultSet(barcode);
}
}
PriceDaoImpl.java:
package com.celerant.dao;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.celerant.dao.PriceDao;
public class PriceDaoImpl extends HibernateDaoSupport implements PriceDao {
@Override
public List getPriceCheckResultSet(String barcode) {
String query =
“SELECT c.brand, c.style, c.description, e.attr1, f.attr2, g.siz, d.price, d.qoh ” +
“FROM TbSkuLookup a INNER JOIN TbSkus b ON (b.skuId = a.skuId) ” +
“INNER JOIN TbStyle c ON (c.styleId = b.styleId) ” +
“INNER JOIN TbSkuBucket d ON (d.skuId = b.skuId) ” +
“LEFT JOIN TbAttr1Entry e ON (e.attr1EntryId = b.attr1EntryId) ” +
“LEFT JOIN TbAttr2Entry f ON (f.attr2EntryId = b.attr2EntryId) ” +
“LEFT JOIN TbSizeEntry g ON (g.scaleEntryId = b.scaleEntryId) ” +
“WHERE a.lookup = ? AND d.storeId = 1″;
return getHibernateTemplate().find(query, barcode);
}
}
In addition to the above files I have several xxx.hbm.xml and model java files per xml file. Can you help me to find why I got the “HibernateQueryException”?
Thanks,
THANK YOU!
Great tutorial ;)
The greatest tutorial ever
thank you M. Yong!!
for this tutorial , it s working !!
this appliction coultn’t run with jBoss server….error is given just like
Please check your file path, applicationContext.xml is missing.
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml
Hi,
I’m trying unsucessfully to run this very good example project on Tomcat 6.0.29.
Here is what i’ve got in console :
Struts Problem Report
Struts has detected an unhandled exception:
Messages:
File: file:/Developer/Applications/apache-tomcat-6.0.29/webapps/Struts2Example/WEB-INF/classes/com/mkyong/customer/action/CustomerAction.java
Line number: 52
50 //list all customers
51 public String listCustomer() throws Exception{
52 customerList = customerBo.listCustomer();
53
54 return “success”;
Stacktraces
java.lang.NullPointerException
com.mkyong.customer.action.CustomerAction.listCustomer(CustomerAction.java:52)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:592)
…
Here are the libs i’m using :
antlr-2.7.6.jar
c3p0-0.9.1.jar
cglib-2.1.3.jar
commons-collections-3.1.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-logging-1.1.jar
dom4j-1.6.1.jar
dsn.jar
ehcache-1.5.0.jar
freemarker-2.3.13.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
hibernate3.jar
imap.jar
javassist-3.12.0.GA.jar
jstl-1.2.jar
jta-1.1.jar
junit-3.8.1.jar
log4j-1.2.16.jar
mail.jar
mailapi.jar
mysql-connector-java-5.1.11-bin.jar
ognl-2.6.11.jar
org.springframework.aop-3.0.4.RELEASE.jar
org.springframework.asm-3.0.4.RELEASE.jar
org.springframework.aspects-3.0.4.RELEASE.jar
org.springframework.beans-3.0.4.RELEASE.jar
org.springframework.context-3.0.4.RELEASE.jar
org.springframework.context.support-3.0.4.RELEASE.jar
org.springframework.core-3.0.4.RELEASE.jar
org.springframework.expression-3.0.4.RELEASE.jar
org.springframework.instrument-3.0.4.RELEASE.jar
org.springframework.instrument.tomcat-3.0.4.RELEASE.jar
org.springframework.jdbc-3.0.4.RELEASE.jar
org.springframework.jms-3.0.4.RELEASE.jar
org.springframework.orm-3.0.4.RELEASE.jar
org.springframework.oxm-3.0.4.RELEASE.jar
org.springframework.spring-library-3.0.4.RELEASE.libd
org.springframework.test-3.0.4.RELEASE.jar
org.springframework.transaction-3.0.4.RELEASE.jar
org.springframework.web-3.0.4.RELEASE.jar
org.springframework.web.portlet-3.0.4.RELEASE.jar
org.springframework.web.servlet-3.0.4.RELEASE.jar
org.springframework.web.struts-3.0.4.RELEASE.jar
pop3.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
smtp.jar
standard.jar
struts2-core-2.1.6.jar
xwork-2.1.2.jar
Do you have any idea ?
I’m not sure if this u already know the answer to this but it happened to me seeing that the beans (customerBO) in this case are not being set by the spring giving nullpointer upon usage, In case u still have this problem, you may try to do this steps
1. make sure that the struts xml class value matches that of the spring bean id. This allows the spring framework to manage the autowiring.
2. add this jar file in your library struts2-spring-plugin-2.2.1.1.jar
let me know if this helps..
Godbless
I don’t know how to run this application could you tell me the steps what i have to do ..
send the steps how to learn please ….
This is Eclipse project, just import it into your Eclipse IDE.
This don’t work
I imported it by maven 2 and more libraries not exists in your maven pom.xml
Please import this project in a new eclipse installation … you will have same problem to execute on tomcat 6
I added three or four libraries in pom.xml because aren’t specfied…
Thank you for your job, but the next time verify pom.xml
Very good for me~!
finally,I have own workable project
Excellent Tutorial Yong. it’s really a Masterpiece.
Thanks a million for your work. I learn many things from this tutorial. :D
Getting an error while deploying on glassfish server
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
Please reply as soon as possible
Pls provides your last caused by error stack.
Getting this error
2 Dec, 2010 12:52:57 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
2 Dec, 2010 12:52:57 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/SSHProject] startup failed due to previous errors
2 Dec, 2010 12:58:27 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
2 Dec, 2010 12:58:27 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/SSHProject] startup failed due to previous errors
How to resolve these errors?
Before SEVERE: Context [/SSHProject] startup failed due to previous errors, it should contains some caused by error stack, copy n paste here.
I am getting following message.
[ERROR] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Compilation failure
C:\workspace\Struts2Example\src\main\java\com\mkyong\customer\dao\impl\CustomerDAOImpl.ja
va:[20,19] generics are not supported in -source 1.3
(try -source 1.5 to enable generics)
public List listCustomer(){
C:\workspace\Struts2Example\src\main\java\com\mkyong\customer\dao\CustomerDAO.java:[11,12
] generics are not supported in -source 1.3
(try -source 1.5 to enable generics)
List listCustomer();
You’re using JDK1.3 to compile the source, which is not support generics function, try get a latest JDK or at least JDK1.5 to compile it.
How do I do that.. I am still having issue with this.
thanks
Yep it’s working fine.
How would you do to manage transactions??
I had the following error :
Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
I have changed from cglib 2.2 to 2.1 and it is working
Thanks for sharing your finding.
I had a hard time getting the source code working with the following tomcat plugin:
org.codehaus.mojo
tomcat-maven-plugin
1.0-beta-1
/Struts2Example
${basedir}/src/main/config/server.xml
My error msg was:
java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(Z)V
Solution: using cglib_nodep jar instead of simple cglib
groupId>cglib
cglib-nodep
2.2
Anyways great tutorial!!!
Hi..
When I shutdown the webserver, I got this error message:
SEVERE: The web application [/Strut2Example] created a ThreadLocal with key of type [null] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@b1be82]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@5b8e8c]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
I’m running using JRE1.6 and Tomcat 7.
Any clue what happens? Did you encounter this error message too?
Hi,
This example is tested un JRE1.6 and Tomcat 6, may be some new features in Tomcat 7. Is the same error message appear every time you shutdown the server?
Hi…
I’ve found the source of the problem. I’m using Eclipse Helios and when I created the project, I used Dynamic Web Module 3.0 (J2EE6?) instead of 2.5. After recreating the project using web module 2.5 the error mentioned previously is gone.
Hi,
A bit of update. I think you are right. After further checking and testing, it’s the tomcat 7 that caused the problem.
Previously I created a new project (with your source code) using web module 2.5 while the project using web module 3.0 was still not deleted. When shutting down the server, the error only showed up on the project using web module 3.0. After I deleted that project, now the error showed up on the project using web module 2.5. Both project were using tomcat 7. So I moved the project using web module 2.5 to tomcat 6 in helios. And it works fine.
Thanks and really appreciated your testing and sharing, noted here. Will give further notice while using Tomcat 7 in future project :)
Any update on this issue yet? got the same problem.
Great tutorial!
Thanks!
Just amazing man!!..
Works like a charm!
Actually BO design pattern’s implementation is exactly what a
customerManager class would have done !..
THANK YOU!