我在應用程序中使用spring-web(4.0.3.RELEASE)以及spring-security-web(3.2.3.RELEASE)。我的目標是在我的應用程序啓動時自動創建一些用戶。然而,當我添加使用用戶的「安全性:用戶...」的標籤,它要麼不創建用戶,或者抱怨Spring Security:創建用戶
Configuration problem: authentication-provider element cannot have
child elements when used with 'ref' attribute
截至目前,我的安全-config.xml文件看起來像這樣。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<security:http auto-config='true'>
<security:intercept-url pattern="/messagebroker/amf" access="ROLE_USER" />
<security:intercept-url pattern="/login.json" access="ROLE_ANONYMOUS" />
</security:http>
<jpa:repositories base-package="com.thing.orlando.repositories" />
<!--authentication manager and password hashing-->
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="daoAuthenticationProvider">
<security:user-service>
<security:user name="admin" password="password" authorities="ROLE_USER, ROLE_ADMIN" />
<security:user name="user" password="password" authorities="ROLE_USER" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
<bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="userDetailsService"/>
<property name="saltSource">
<bean class="org.springframework.security.authentication.dao.ReflectionSaltSource">
<property name="userPropertyToUse" value="email"/>
</bean>
</property>
<property name="passwordEncoder" ref="passwordEncoder"/>
</bean>
<bean id="userDetailsService" name="userAuthenticationProvider"
class="com.dallas.orlando.services.CustomUserDetailsService"/>
<bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder">
<constructor-arg index="0" value="256"/>
</bean>
我想知道什麼是創建用戶並填充我的分貝接受的方式。
我已經嘗試過,並且根據您的回覆再次執行了此操作。在這種情況下,沒有用戶被創建。看看日誌,我可以看到Hibernate創建表,但沒有找到「Insert blach ..」的實例。 =( –
)因爲這兩個用戶只存儲在內存中,如果你想將它們存儲在數據庫中,你需要在應用程序啓動時使用SQL腳本來插入數據。這些用戶的? – JamesENL
它是否工作?如果它沒有更多的東西可以嘗試 – JamesENL