首页 > 解决方案 > spring security sql-error-codes.xml ,没有发现异常跟踪

问题描述

我已经为我的应用程序配置了 spring 安全性,但由于以下信息而卡在一个地方:org.springframework.beans.factory.xml.XmlBeanDefinitionReader-从类路径资源加载 XML bean 定义 [org/springframework/jdbc/support/sql-错误代码.xml]。我有谷歌但找不到原因

我的代码:-

<beans:beans
    xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security-3.2.xsd">

    <http security="none" pattern="/login"></http>
    <http auto-config="false" use-expressions="true">
        <intercept-url pattern="/*" access="hasRole('ROLE_USER')" />

        <!-- login-processing-url="" -->
        <form-login login-page="/login" default-target-url="/" authentication-failure-url="/login?error" username-parameter="username" password-parameter="password" />
        <logout logout-success-url="/login?logout" invalidate-session="true" />
    </http>

    <!-- <authentication-manager>
        <authentication-provider>
            <jdbc-user-service data-source-ref="dataSource" />
        </authentication-provider>
    </authentication-manager> -->


    <authentication-manager>
        <authentication-provider>
            <jdbc-user-service data-source-ref="dataSource"
                users-by-username-query="SELECT USERNAME,PASSWORD,ENABLED from SCOTT.TBL_USERS WHERE USERNAME=?;"
authorities-by-username-query="SELECT u.USERNAME, r.ROLENAME FROM SCOTT.TBL_USERS u,SCOTT.TBL_USER_ROLE r WHERE u.USERNAME = r.USERNAME 
    AND u.USERNAME=?;" />
        </authentication-provider>
    </authentication-manager>

     <beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <beans:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <beans:property name="url" value="jdbc:oracle:thin:@192.168.6.147:1521:orcl" />
        <beans:property name="username" value="SCOTT" />
        <beans:property name="password" value="IPORTMAN" />
    </beans:bean> 
</beans:beans>

我创建了自己的表:- CREATE TABLE "SCOTT"."USERS" ("USERNAME" VARCHAR2(50) NOT NULL PRIMARY KEY, "PASSWORD" VARCHAR2(50) NOT NULL, "ENABLED" NUMBER(22 , 0) NOT无效的 );

创建表“SCOTT”。“TBL_USER_ROLE”(用户名varchar(50)不为空,权限varchar(50)不为空,约束fk_authorities_users外键(用户名)引用“SCOTT”。“TBL_USERS”(用户名));我如何追踪问题,为什么我的登录总是失败,我的登录页面出现了我已经给出了用户名和密码,但它只是在控制台 sql-error-codes.xml 中弹出。

标签: javaspringhibernatespring-securityspring-orm

解决方案


when we are using Oracle database then the table structure is like below
CREATE TABLE users (username VARCHAR(50) PRIMARY KEY, password VARCHAR(50) NOT NULL, enabled VARCHAR(50) NOT NULL)
  create table authorities (
      username varchar(50) not null,
      authority varchar(50) not null,
      constraint fk_authorities_users foreign key(username) references users(username));
      create unique index ix_auth_username on authorities (username,authority);

the problem was in table structure.

推荐阅读