Hi, I have changed the code and used the imp class methods but still having the same exception, here is my code and hop you can help me:
LoginAction: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package action; import com.opensymphony.xwork2.ActionSupport; import java.util.Locale; import org.springframework.context.support.ResourceBundleMessageSource; import po.User; import service.UserService; import service.UserServiceImp; /** * * @author ABIS1 */ public class LoginAction extends ActionSupport { private UserService usrService; private UserServiceImp userService; private String message; private String username; private String password; private ResourceBundleMessageSource messageSource; public LoginAction() { } @Override public String execute() throws Exception { User usr= userService.getUser(username); if(usr != null){ if(usr.getPassword().equals(password)){ message = messageSource.getMessage("loginSuccess", null,Locale.UK); }else{ message = messageSource.getMessage("pswError", null,Locale.UK); } }else{ message = messageSource.getMessage("usrError", null,Locale.CHINA); } return SUCCESS; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public UserServiceImp getUserService() { return userService; } public void setUserService(UserServiceImp userService) { this.userService = userService; } public void setMessageSource(ResourceBundleMessageSource messageSource) { this.messageSource=messageSource; } public ResourceBundleMessageSource getMessageSource() { return messageSource; } public void setUserService(UserService usrService) { this.usrService = usrService; } } UserDaoImpl: package dao; import po.*; import dao.UserDao; import java.util.List; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; /** * * @author ABIS1 */ public class UserDaoImpl extends HibernateDaoSupport implements UserDao { public void save(User user) throws Exception { try { getHibernateTemplate().save(user); } catch(Exception err) { throw err; } } public User getUser(long userId) { return (User)getHibernateTemplate().get(User.class, userId); } public User getUser(String userName) { return(User) getHibernateTemplate().find("from User as u where u.name = ?", userName).get(0); } } UserServcieImpl: package service; import po.User; /** * * @author ABIS1 */ public class UserServiceImp implements UserService { private dao.UserDao userDao; public void addUser( String userName, String password) throws Exception{ po.User user = new User(); user.setName(userName); user.setPassword(password); try { userDao.save(user); } catch(Exception err) { throw err; } } public User getUser(long userId) { return userDao.getUser(userId); } public void setUserDao(dao.UserDaoImpl userDao) { this.userDao = userDao; } public User getUser(String userName) { return this.userDao.getUser(userName); } } ApplicationContext.xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans default-autowire="autodetect"> <!-- add your spring beans here --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/sshdemo"/> <property name="username" value="root"/> <property name="password" value=""/> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mappingResources"> <list> <value>po/user.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <value>hibernate.dialect=org.hibernate.dialect.MySQLDialect</value> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory"><ref bean="sessionFactory" /></property> </bean> <bean id="userDao" class="dao.UserDaoImpl"> <property name="hibernateTemplate"> <ref bean="hibernateTemplate"></ref> </property> </bean> <bean id="userService" class="service.UserServiceImp"> <property name="userDao"> <ref bean="userDao"></ref> </property> </bean> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="messages" /> </bean> <bean id="loginAction" class="action.LoginAction"> <property name="userService"> <ref bean="userService"></ref> </property> <property name="messageSource" ref="messageSource"/> </bean> </beans> Struts.xml <struts> <include file="example.xml"/> <!-- Configuration for the default package. --> <package name="default" extends="struts-default"> <action name="login" class="action.LoginAction"> <result>example/message.jsp</result> </action> </package> </struts> Thannks. -----Original Message----- From: Wes Wannemacher [mailto:w...@wantii.com] Sent: 20 August 2009 19:44 To: Struts Users Mailing List Subject: Re: Hibernate3+Spring2.5+Struts2 On Thu, Aug 20, 2009 at 12:38 PM, Zied Bejaoui<bejaouiz...@hotmail.com> wrote: > Thanks for the help guys. > > change User usr= userService.getUser(username); > to User usr=userServiceImp.getUser(username); > > userService is a UserServiceImp instance--> UserServiceimp userService. > You were on the right track before, you just want the following in your class - ->snippet private UserService userService; public void setUserService(UserService userService) { this.userService = userService; } <- end snippet I am curious if it's 'userService' that is null... This would mean that your action isn't being wired with the service from Spring. I snipped all the previous messages from this email, so i can't look through it for you, but I will say that this sort of thing is generally a simple property misspelling or some other detail (decimal point? I always mess up some mundane detail). If it's username that is null, you might want to check that your form is properly setup in your JSP. -Wes -- Wes Wannemacher Head Engineer, WanTii, Inc. Need Training? Struts, Spring, Maven, Tomcat... Ask me for a quote! --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org