1

我使用 spring security:jdbc-user-service 创建了一个登录模块。但是我收到了 SQLErrorCode 异常,下面是我的代码。

数据源bean:

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
          destroy-method="close">

        <property name="driverClass" value="${jdbc.driverClassName}" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="user" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />


        <property name="minPoolSize" value="1" />
        <property name="maxPoolSize" value="1" />

    </bean>

安全认证:

<security:http auto-config='true'>
    <security:intercept-url pattern="/**" access="ROLE_USER" />
    <security:form-login login-page='/login'
                         default-target-url='/' always-use-default-target='true' />
</security:http> 

   <security:authentication-manager>
        <security:authentication-provider>
            <security:jdbc-user-service data-source-ref="dataSource"
                                        users-by-username-query="select username,password,enabled from userdetails where username=?"
                                        authorities-by-username-query="select u.username, ur.authority from userdetails u, userrole ur 
              where u.id = ur.userid and u.username =?  " 
            />

        </security:authentication-provider>

例外:

org.springframework.beans.factory.support.DefaultListableBeanFactory - Overriding bean definition for bean 'H2':
 replacing [Generic bean: class [org.springframework.jdbc.support.SQLErrorCodes]; scope=; abstract=false; lazyInit=fals
e; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=nu
ll; initMethodName=null; destroyMethodName=null; defined in class path resource [org/springframework/jdbc/support/sql-e
rror-codes.xml]] with [Generic bean: class [org.springframework.jdbc.support.SQLErrorCodes]; scope=; abstract=false; la
zyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMe
thodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [sql-error-codes.xml]]

当我使用 security:user-service provider 时,它工作正常,但是通过使用 JDBC provider,我得到了这个异常,我的 security:user-service 代码如下:

<security:user-service>
        <security:user name="admin" password="admin"
                           authorities="ROLE_USER, ROLE_ADMIN" />
        <security:user name="talha" password="talhapassword"
                           authorities="ROLE_USER" />
    </security:user-service>
4

0 回答 0