Berikut Lengkapnya :

applicationContext.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";
       xmlns:p="http://www.springframework.org/schema/p";
       xmlns:context="http://www.springframework.org/schema/context";
       xmlns:tx="http://www.springframework.org/schema/tx";
       xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
       http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd";>

    <context:annotation-config/>
    <context:component-scan base-package="*"/>
    <tx:annotation-driven/>

    <bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>java:comp/env/jdbc/datasource</value>
        </property>
    </bean>

    <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation"
value="classpath:hibernate.cfg.xml"/>
    </bean>

    <bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
</beans>

================================================================================================


springapp-servlet.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";
       xmlns:p="http://www.springframework.org/schema/p";
       xmlns:aop="http://www.springframework.org/schema/aop";
       xmlns:tx="http://www.springframework.org/schema/tx";
       xmlns:context="http://www.springframework.org/schema/context";
       xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
       http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
       ">

    <context:annotation-config/>
    <context:component-scan base-package="*"/>

    <bean id="viewResolver"

class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp" />
</beans>
=================================================================================================


hibernate.cfg.xml
=================================================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate
Configuration DTD 3.0//EN" "
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd";>
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.show_sql">true</property>

    <property
name="hibernate.current_session_context_class">thread</property>
    <property
name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
    <!--property name="hibernate.use_sql_comments">true</property-->
    <mapping resource="model/User.hbm.xml"/>
  </session-factory>
</hibernate-configuration>
=================================================================================================

LoginController.java
=================================================================================================
package controller;

import javax.servlet.http.HttpServletRequest;
import model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import service.UserService;

@Controller
public class LoginController {

    private UserService userService;

    @RequestMapping("/login")
    public String login(HttpServletRequest request){
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);

        User userResult = userService.login(user);

        if (userResult == null) return "redirect:/index.jsp";
        else return "redirect:/main.jsp";
    }

    public UserService getUserService() {
        return userService;
    }

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
}
=================================================================================================

UserDaoImpl.java

=================================================================================================
package dao.impl;

import dao.UserDao;
import model.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("userDao")
public class UserDaoImpl implements UserDao {

    private SessionFactory sessionFactory;

    public User login(User user) {
        Session session = sessionFactory.getCurrentSession();

        User userResult = null;

        String querySql = "from User u where u.username = :username and
u.password = :password";

        userResult = (User) session.createQuery(querySql)
                .setString("username", user.getUsername())
                .setString("password", user.getPassword()).uniqueResult();

        return userResult;
    }


    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
}
=================================================================================================

UserServiceImpl.java

================================================================================================
package service.impl;

import dao.UserDao;
import dao.impl.UserDaoImpl;
import model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import service.UserService;

@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
    private UserDao userDao;

    public User login(User user) {
        return userDao.login(user);
    }

    public UserDao getUserDao() {
        return userDao;
    }

    @Autowired
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }


}
=================================================================================================


Maap kalau kepanjangan..apakah ada yang salah ?? soalnya error hanya muncul
kalau pakai HQL.

Kirim email ke