spring java项目中发生数据库错误

时间:2014-07-19 10:45:18

标签: java mysql spring spring-mvc

使用数据库mysql和服务器的spring java项目使用jetty服务器弹出安全性直接在控制台上出错。

错误显示在控制台

 [INFO] Started Jetty Server
Jul 19, 2014 3:54:22 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
Jul 19, 2014 3:54:22 PM org.springframework.jdbc.support.SQLErrorCodesFactory <init>
INFO: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
Hibernate: select this_.ID as ID23_1_, this_.CREATED_DATE as CREATED2_23_1_, this_.IS_DELETE as IS3_23_1_, this_.DEPARTMENT_ID as DEPARTMENT9_23_1_, this_.EMAIL_ID a
s EMAIL4_23_1_, this_.FIRST_NAME as FIRST5_23_1_, this_.LAST_NAME as LAST6_23_1_, this_.PASSWORD as PASSWORD23_1_, this_.USERNAME as USERNAME23_1_, department2_.ID a
s ID16_0_, department2_.CREATED_DATE as CREATED2_16_0_, department2_.IS_DELETE as IS3_16_0_, department2_.NAME as NAME16_0_ from user this_ inner join department dep
artment2_ on this_.DEPARTMENT_ID=department2_.ID where this_.USERNAME=?

弹簧security.xml文件

<security:http use-expressions="true">

        <security:form-login login-page="/home.html"

   default-target-url="/dologin.html" authentication-failure-url="/loginfailed.html" />
        <!-- <security:logout logout-success-url="/home.html"/> -->

        <security:logout logout-success-url="/Loggedout.html" />
        <security:remember-me />
        <security:intercept-url pattern="/signin*"
            access="permitAll" />
    </security:http>

    <security:authentication-manager>

        <security:authentication-provider>

            <security:jdbc-user-service
                data-source-ref="dataSource"
                users-by-username-query="
              select username,password 
              from users where username=?"

                authorities-by-username-query="
              select u.username, ur.users_id from users u, user_role ur 
              where u.id = ur.users_id and u.username =?  " />

        </security:authentication-provider>

    </security:authentication-manager>

控制器

@RequestMapping("/home.html")
public String getHomePage() {

    return "/index";
}

@RequestMapping("/")
public String root() {
    return "redirect:/home.html";
}

@RequestMapping("/dologin.html")
public String doLogin() {
    String path = null;
    System.out.println("Inside Do Login *********************");
    User user = (User) SecurityContextHolder.getContext()
            .getAuthentication().getPrincipal();
    System.out.println(user+"User****************");

    if (userHasRole("ROLE_USER")) {
        System.out.println(securityDAO.getLoggedUserAccount());
        path = "redirect:/home.html";
    }
    if (userHasRole("ROLE_ADMIN")) {
        System.out.println("admin****************");
        path = "redirect:/Adminhome.html";
    }

    return path;
}

@RequestMapping("/loginfailed.html")
String loginFailed(ModelMap modelMap) {
    modelMap.addAttribute("error", "False");
    System.out.println(securityDAO.getLoggedUserAccount()+"Fffffffffffff");
    return "/index";
}

始终控制转到loginfailed.html,securityDAO.getLoggedUserAccount()显示空值。

如果你知道这个错误请坚持这个错误请分享答案

0 个答案:

没有答案