Error with LogIn with mysql database

Error with LogIn with mysql database

Hi, I have followed steps from your tutorial titled SpringMVClogin with database. I am not using Jetty, as I have Tomcat as my server using Eclipse IDE. When I run the program I get a Http 404 page error. In Tomcat console it states the reason as:

"Error creating bean with name 'loginController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.pizza.service.LoginService com.pizza.controllers.LoginController.loginService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.pizza.dao.LoginDAO com.pizza.service.LoginServiceImpl.loginDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginDAO': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration"

My Code reads as follow:

Controller

package com.pizza.controllers;

import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.validation.BindingResult; import org.springframework.validation.ObjectError; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration;

import java.util.Map; import javax.validation.Valid;

import com.pizza.form.LoginForm; import com.pizza.service.*;

@Controller @RequestMapping("loginform.html") @Configuration @ComponentScan("com.pizza.service") public class LoginController {

@Autowired
public LoginService loginService;

@RequestMapping(method = RequestMethod.GET)
public String showForm(Map model) {
    LoginForm loginForm = new LoginForm();
    model.put("loginForm", loginForm);
    return "loginform";
}

@RequestMapping(method = RequestMethod.POST)
public String processForm(@Valid LoginForm loginForm, BindingResult result,
        Map model) {


    if (result.hasErrors()) {
        return "loginform";
    }

    /*
    String userName = "UserName";
    String password = "password";
    loginForm = (LoginForm) model.get("loginForm");
    if (!loginForm.getUserName().equals(userName)
            || !loginForm.getPassword().equals(password)) {
        return "loginform";
    }
    */
    boolean userExists = loginService.checkLogin(loginForm.getUserName(),loginForm.getPassword());
    if(userExists){
        model.put("loginForm", loginForm);
        return "loginsuccess";
    }else{
        result.rejectValue("userName","invaliduser");
        return "loginform";
    }

}

}

DAO

package com.pizza.dao; import com.pizza.model.Users;

public interface LoginDAO{
public boolean checkLogin(String userName, String userPassword); }

DAO Impl

package com.pizza.dao; import com.pizza.model.Users;

import org.springframework.stereotype.Component; import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Query; import java.util.List;

@Repository("loginDAO") public class LoginDAOImpl implements LoginDAO{

   @Resource(name="sessionFactory")
   protected SessionFactory sessionFactory;

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

   protected Session getSession(){
          return sessionFactory.openSession();
   }

   @Override
public boolean checkLogin(String userName, String userPassword){
        System.out.println("In Check login");
        Session session = sessionFactory.openSession();
        boolean userFound = false;
        //Query using Hibernate Query Language
        String SQL_QUERY =" from Users as o where o.userName=? and o.userPassword=?";
        Query query = session.createQuery(SQL_QUERY);
        query.setParameter(0,userName);
        query.setParameter(1,userPassword);
        List list = query.list();

        if ((list != null) && (list.size() > 0)) {
            userFound= true;
        }

        session.close();
        return userFound;              
   }

}

Service

package com.pizza.service; import com.pizza.model.Users;

public interface LoginService{
public boolean checkLogin(String userName, String userPassword); }

package com.pizza.service;

import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;

import com.pizza.dao.*;

@Service("loginService") public class LoginServiceImpl implements LoginService {

 @Autowired
 private LoginDAO loginDAO;

   public void setLoginDAO(LoginDAO loginDAO) {
          this.loginDAO = loginDAO;
   }

   public boolean checkLogin(String userName, String userPassword){
       System.out.println("In Service class...Check Login");
       return loginDAO.checkLogin(userName, userPassword);
}

}

Model

package com.pizza.model;

import java.util.List; import java.io.Serializable; import java.sql.Timestamp;

import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Column; import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.JoinColumns; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Transient; import javax.persistence.Embeddable;

@Entity @Table(name = "users") @SuppressWarnings("serial") public class Users implements Serializable {

@Id
@GeneratedValue
@Column(name = "id", length = 11 )
private Long id;

@Column(name = "user_name")
String userName;

@Column(name = "user_password")
String userPassword;



public Long getId() {
    return id;
}


public void setId(Long id) {
    this.id = id;
} 




public String getUserName() {
    return userName;
}

public void setUserName(String userName) {
    this.userName = userName;
}

public String getUserPassword() {
    return userPassword;
}

public void setUserPassword(String userPassword) {
    this.userPassword = userPassword;
}

}

application context

<!-- Base package for checking the annoted classes -->
  <context:component-scan base-package="com.pizza"></context:component-scan>



  <!-- Configure JDBC Connection-->
  <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/pizzaStore" />
        <property name="username" value="root" />
        <property name="password" value="root" />
  </bean>

  <!-- Configure Hibernate 4 Session Facotry -->
  <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.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="annotatedClasses">
        <list>
              <value>com.pizza.model.Users</value> <!-- Entity classes-->
        </list>
        </property>

  </bean>

Web XML

<display-name>My Pizza App</display-name>

<servlet>
    <servlet-name>springMVCpizza-servletConfig</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>springMVCpizza-servletConfig</servlet-name>
    <url-pattern>/forms/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

contextConfigLocation classpath:applicationContext.xml

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

View Answers

Ads









Related Tutorials/Questions & Answers:
Error with LogIn with mysql database
Error with LogIn with mysql database  Hi, I have followed steps from your tutorial titled SpringMVClogin with database. I am not using Jetty, as I... 404 page error. In Tomcat console it states the reason as: "Error creating bean
login page using jsp servlrt with mysql database?
login page using jsp servlrt with mysql database?  Description: example:total users are 3.each use have username and password save in mysql database table login. After successfully login user1 see only index page,if user2 login
Advertisements
Spring 3 MVC Login Form Example with Database MySql
Spring 3 MVC Login Form Example with Database MySql  Sir i have checked your project of Spring 3 MVC Login Form Example But Sir Not able to do It with database Mysql. Can you Provide code for login with database. Thanks
simple code to login user & authenticate it from database mysql
simple code to login user & authenticate it from database mysql  Sir, I am creating a login page which contain userid & password. Iwant to authenticate user from mysql database. please tell me the code for it. Thanks
How to view database for user when they login in netbeans and mysql?
How to view database for user when they login in netbeans and mysql?  I create a web page where when user login they have to fill in a form, after... but it come out with all the other user information too. I'm using netbeans and mysql
LOGIN ERROR
LOGIN ERROR  ERROR SCRIPT: LOGIN FAILED", $_SESSION['login fail']='0',}?> Ty Team
login page with mysql using jsp
login page with mysql using jsp  pls i need a sample of login page to check username and password in mysql database. thanks
JSP Login Form with MySQL Database Connection and back end validation
Here we have created a simple login form using MySQL Database Connection... to create JSP Login form backed with MySQL database: The following image... database and matched with the input value given through the login form. Example
MYSQL Database
MYSQL Database  Can any one brief me about how to use MYSQL Database to store the create new database, create tables. Thanks.   Hi, the MySQL database server is most popular database server and if you want to know
login page error
login page error  How to configure in to config.xml .iam takin to one login form in that form action="/login" .when iam deployee the project following error arise ."The server encountered an internal error (No action instance
Spring Login Page Error
Spring Login Page Error  Dear Sir/Madam, I used the spring login page code. The index page is working fine. When i try to entry login and password , i am getting the below error: Please help me out in this. Let me know if i
update mysql database
update mysql database  update mysql database
login page php mysql example
login page php mysql example  How to create a login page for user in PHP Mysql? Please provide me a complete tutorial. Thanks in Advance
XML parsing to Mysql database
XML parsing to Mysql database  Can someone please post the code for parsing an XML file into Mysql database using SAX
Connecting to MYSQL Database in Java
Connecting to MYSQL Database in Java  I've tried executing the code below but the error that I get is "Error: com.mysql.jdbc.Driver" I downloaded... from database"); } catch (Exception e) { System.out.println("Error
error oracle database connection?
error oracle database connection?  hi now i am trying to connect oracle database and also insert my data into table, but it's not working.. I created... = con.prepareStatement("insert into login_info_client_sla values
java code for registration and login pages, mysql as a bankend.
java code for registration and login pages, mysql as a bankend.  please send me the java code for registration and login pages and to store the data in mysql
Database error - WebSevices
Database error  Hello, How i connect my database file& tables to Zend library file Using PHP language. In which library file i should change that code. Any one know the exact changes. Tell me.   http
Create Database and tables in MySQL
and tables in MySQL Database? Explain me step-by-step as I am beginner in MySQL. Thanks   Hi, First of all you have to connect to MySQL database through command line tool. Connecting to MySQL Database: mysql -uroot -p Here
connection database error
connection database error  import java.awt.EventQueue; // import packages import java.awt.event.ActionEvent; import java.awt.event.ActionListener...;which type of error occurs? Specify it. Is NWIND is your dsn
MySQL 5.1 upgrade to 5.5 error
MySQL 5.1 upgrade to 5.5 error  MySQL 5.1 upgrade to 5.5 error
MySQL 5.1 upgrade to 5.5 error
MySQL 5.1 upgrade to 5.5 error  MySQL 5.1 upgrade to 5.5 error
Database connectivity Hibernate mysql connection.
Database connectivity Hibernate mysql connection.  How to do database connectivity in Hibernate using mysql
what is the mysql in the database using php
what is the mysql in the database using php  what is the mysql in the database using php  Please visit the following link: PHP Database
what is the mysql in the database using php
what is the mysql in the database using php  what is the mysql in the database using php  Please visit the following link: PHP Database
error log and send Database
error log and send Database  hi my requirement is validate xml and xsd in java.If there is an errors then i will log error and store into error table. so plz if any one knows send code urgent. error table details
validating username and password in servlet and redirect to login page with error message if not valid
validating username and password in servlet and redirect to login page with error message if not valid  hi i want to validate my login page username... error message saying "Invalid username and password" in my login page. please help
database connectivity using mysql
database connectivity using mysql  java file: eg1.java package eg...[]) throws SQLException { try { String connectionURL = "jdbc:mysql... ex) { System.out.println(ex); } } } error: init: deps-module-jar
Setup MySQL Database
Setup MySQL Database      ... into MySQL database. Table created here will be used in sample application.../mysql/mysql5/Installing-MySQL-on-Windows.shtml Creating Database : You can create mysql database
MySQL Create Database
MySQL Create Database        ... to create the database on MySQL Server. MySQL Database server is one of the very... of the database server. MySQL comes with the easy to use the command line tool through
login
login  how to login admin and user with the same fields(name & password) in single login page while the table for admin and user is seprate in database(mysql) please provide me solution

Ads