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









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
LOGIN ERROR
LOGIN ERROR  ERROR SCRIPT: LOGIN FAILED", $_SESSION['login fail']='0',}?> Ty Team
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 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
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
JSP Login Form with MySQL Database Connection and back end validation
Here we have created a simple login form using MySQL Database Connection... Following video will help you to create JSP Login form backed with MySQL database... database and matched with the input value given through the login form. Example
login error - WebSevices
login error   To customer service, I have found this type of error from JAVA WebService.(Connection is completed.) At the first login time this error is coming and after that working properly.. The error is quated below
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
Error in connecting to the mySQL database in TOMCAT using more than one PC (database connection pooling)
Error in connecting to the mySQL database in TOMCAT using more than one PC (database connection pooling)  how do i implement connection pooling...="com.mysql.jdbc.Driver" url="jdbc:mysql://10.9.58.8:3306/alcs_htht"/> </Context>
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 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
Login authentication & mysql - Java Beginners
their personal account with the username and password, must save it in database (MySQL...{ JOptionPane.showMessageDialog(null,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE...Login authentication & mysql  Hi , Could you guide or provide
update mysql database
update mysql database  update mysql database
Database Error - Hibernate
Database Error  Hi, I am working with Struts 1.2---- AJAX-----Hibernate 3.0 --- MySQL 5.0. At the time of inserting/fetching from Database... exceeded; try restarting transaction That means the database becomes locked. Can
Database - mysql - SQL
Database - mysql size limit  What is the size limit for any mysql database
Applet to database error - Applet
Applet to database error  Hi... I had an application where i need to connect to the database for the values to display in the applet.... Following...=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","username","password
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
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
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
Oracle Database error - JDBC
Oracle Database error   String query11 = "SELECT product_code, product_quantity, price FROM o"+orderid; ResultSet rs11... = DriverManager.getConnection("jdbc:mysql://localhost:3306/register", "root", "root"); Statement
insert images into a Mysql database
insert images into a Mysql database  How can I insert images into a Mysql database
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
PHP MySQL Login Form
Login Form using PHP and MySQL: In any website generally it is mandatory... will study how to create a login form, connect with the database server and login...;      die('Connection Failed'.mysql_error()); }ADS
error in accessing database - JSP-Servlet
error in accessing database  hiiii im tanushri im tryng to connect my database to the servlet i hv succeeded in connectivity but im stuck to nother error called Got minus one from read call although i hv feeded data to my
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
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
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
validating credentials and displaying error message in login .jsp if not valid
validating credentials and displaying error message in login .jsp if not valid  hi, i want to validate user name and password against my database table if not valid i have to display error message in my login page.how to do
getting error in your login form code
getting error in your login form code  i tried your code for login form but i am getting an error.the error is undefined index userid and password.the code is $fuser=$POST["userid"];. how to solve this problem please help me
java database error - JDBC
java database error  hi all i am writing one swing application where i want to insert data into database(MS-Access) but dont know how to do... the following code to insert the data into MS-Access database: import java.sql.
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
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
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
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
Database driven login form - Java Server Faces Questions
Database driven login form  Dear sir,madam, Greetings!! well, am... is code that; will create a database driven login form where users are authenticated only if their names and passwords are stored in a mysql database. thank you
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
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
MySql database - SQL
MySql database  hello sir, i am trying to write a code which should... to retrieve the data from Ms-access then you create a database , table and create a connection with this. Then you retrieve the data from the database. Thanks
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
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
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?  how to connect jsp with sql database by netbeans in a login page
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?  how to connect jsp with sql database by netbeans in a login page
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?  how to connect jsp with sql database by netbeans in a login page
Submit button to MySQL database?
Submit button to MySQL database?  Need help linking html code to mysql database <html> <head> <meta http-equiv="Content-Type...").newInstance(); Connection connection = DriverManager.getConnection("jdbc:mysql

Ads