Struts + Spring + Hibernate integration example

Download this Struts 1.x + Spring + Hibernate example – Struts-Spring-Hibernate-Example.zip

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..

  1. Integrate Spring with Hibernate with Spring’s “LocalSessionFactoryBean” class.
  2. Integrate Spring with Struts via Spring’s ready make Struts plug-in – “ContextLoaderPlugIn“.

1. Project Structure

This is this final project structure.

struts-spring-hibernate-1
struts-spring-hibernate-2

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"%>
 




Struts + Spring + Hibernate example

Add Customer

:
:

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"%>
 




Struts + Spring + Hibernate example

List All Customers

Customer NameAddress


Add Customer

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

struts-spring-hibernate-demo-1

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

struts-spring-hibernate-demo-2

Reference

  1. Struts + Spring example
  2. Struts + Hibernate example
  3. Spring + Hibernate example

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
fiky yuvita
Guest
fiky yuvita

Hai Mr Mkyong, i want to ask, what is the difference between CustomerBo and CustomerDao. Because the method is same. Pardon for my english and tengkyu for your answer.

meenu
Guest
meenu

You website is really very good.

mallikarjun
Guest
mallikarjun

Hi meenu,

Your communication is very poor ….. Pls dont kill the people

Mallikarjun

Chandu Damarasingh
Guest
Chandu Damarasingh

which archetype am choose please send me

Minnie
Guest
Minnie

Hey,guys ! if you just download the example ,got 404 error when you try to run it
just add this to pom.xml,it will works

org.springframework
spring-beans
2.0.8

org.springframework
spring-context
2.0.8

org.springframework
spring-core
2.0.8

commons-beanutils
commons-beanutils
1.8.0

Sandeep Shukla
Guest
Sandeep Shukla

Could you please upload the working example as war files.

Sandeep Shukla
Guest
Sandeep Shukla

Hi,

I tried the above example but I am getting following exception

Sep 15, 2014 8:07:38 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /springstrutsexample threw load() exception
javax.servlet.UnavailableException: Parsing error processing resource path
at org.apache.struts.action.ActionServlet.handleConfigException(ActionServlet.java:1035)
at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:1012)
at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:955)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:470)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Sep 15, 2014 8:07:38 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [“http-bio-8080”]
Sep 15, 2014 8:07:38 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [“ajp-bio-8009”]
Sep 15, 2014 8:07:38 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2085 ms

A
Guest
A

Can you explain the flow? Can you put the flow explanation before the code.

Rashmi
Guest
Rashmi

Hi MKyong,

I am new to hibernate.. I am having one issue in my project. the “getHibernateTemplate().find(query, args);” Fails with table or view not found. i have verified all these table names etc.. my question is can i have the caller in a different jar from the xxxx.hbm.xml ? i.e my caller which calls – getHibernateTemplate().find ” is in AAA.jar and the hbm.xml is in different Jar. is this causing the above table not found issue?

lch
Guest
lch

Hi MKyong, Could you add instruction how to run this project on eclipse or tomcat.

DuongLx
Guest
DuongLx

Hi MKyong,
Please help me, how to run project in eclipse ?
Tks !

ashok
Guest
ashok

ashok
very nice example,thanku
can you provide ‘customer mangement system’ project flow and architeur pls send me

Dev
Guest
Dev

Dev – Hi Kyong,
very nice example, thanks for sharing it.
can you please provide the jar files? you are using M2_REPO I am not able to find all jars on net
Also for mysql I am using 5.6.15, can you please help where can i find jar for it? thanks

Nitin Bansal
Guest
Nitin Bansal

anyone can help me…? i just want a small project in struts and hibernates based so i can learn the things and i will try to extend the project and by that i can go for interviews and all please if anyone can help me

Sanjay
Guest
Sanjay

Hi MKyong,
Could you please attach the screen shot for jar files.
thanks in advance

Sujith
Guest
Sujith
I got the bellow error when publishing Nov 14, 2013 12:00:09 AM org.springframework.web.struts.ContextLoaderPlugIn init SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’ defined in Servl etContext resource [/WEB-INF/classes/config/database/spring/HibernateSessionFactory.xml]: Invocation of init method fail ed; nested exception is org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.en tity.PojoEntityTuplizer] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireC apableBeanFactory.java:1338) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCap ableBeanFactory.java:473) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBea nFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapab leBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegis try.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListable BeanFactory.java:423) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplic ationContext.java:728) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380) at org.springframework.web.struts.ContextLoaderPlugIn.createWebApplicationContext(ContextLoaderPlugIn.java:354) at org.springframework.web.struts.ContextLoaderPlugIn.initWebApplicationContext(ContextLoaderPlugIn.java:295) at org.springframework.web.struts.ContextLoaderPlugIn.init(ContextLoaderPlugIn.java:225) at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:869) at org.apache.struts.action.ActionServlet.init(ActionServlet.java:336) at javax.servlet.GenericServlet.init(GenericServlet.java:212) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1206) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)… Read more »
Sujith
Guest
Sujith

Hi mkyong,
Why I’m getting above error when publishing to tomcat 6

Krish
Guest
Krish

Hi Mkyong

I am getting this error.when i start my tomcat(5.5) server

SEVERE: Error reading tld listeners java.lang.NullPointerException
java.lang.NullPointerException
at org.apache.log4j.Category.isEnabledFor(Category.java:749)
at org.apache.commons.logging.impl.Log4JLogger.isTraceEnabled(Log4JLogger.java:333)

anon
Guest
anon

hey mr mkyong tk u for this tutoriel so can u give us a same tuto but with a relation many to one and many to many tk u

Harikrishna
Guest
Harikrishna

Hi,
What is the maven command you used to get this folder structure.(or). How did you get this folder structure.

Anbarasan
Guest
Anbarasan

HI hari krishna you just gothrough the maven in this same forum

sharocks
Guest
sharocks

Hi Mkyong,

Can you please let me know how to upgrade asm dependency. Because, it is currently showing asm-1.5.3 jar. But in previous comments, you have asked to upgrade to asm-3.1. Please help me in this case.

Mau Vu Huu
Guest
Mau Vu Huu

Hi yong,

I get the following error when deploying the sample on tomcat 7.0.40. Please help ?

SEVERE: Parsing error processing resource path /WEB-INF/struts-config.xml
java.net.UnknownHostException: jakarta.apache.org
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.http.HttpClient.(HttpClient.java:233)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:323)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:860)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:801)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:726)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049)
at org.apache.commons.digester.Digester.createInputSourceFromURL(Digester.java:1938)
at org.apache.commons.digester.Digester.resolveEntity(Digester.java:1615)
at com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.resolveEntity(EntityResolverWrapper.java:107)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntityAsPerStax(XMLEntityManager.java:1018)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1192)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1090)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1003)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.apache.commons.digester.Digester.parse(Digester.java:1745)
at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:738)
at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:687)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:333)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5407)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1654)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)

Ashok Yarrabati
Guest
Ashok Yarrabati

have u got the answer from any one i am also has got same exception

cars
Guest
cars

It should be fun to buy a new car! Driving a new car
is such a great experience, and purchasing the car should be
fun as well. A lot of people would rather skip the whole purchasing process.
Keep the stress to a minimum using these tips.

sabari
Guest
sabari

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

kranthi
Guest
kranthi

how to create project structure in eclipse please help me

Renjith
Guest
Renjith

All your tutorials are very easy and helpful. Thank you and keep up the good work!

ardi priasa
Guest
ardi priasa

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

Mohan Rao
Guest
Mohan Rao

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.

Manish
Guest
Manish

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

Manish
Guest
Manish

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

sidd
Guest
sidd

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

sant
Guest
sant
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)
takis
Guest
takis

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?