【发布时间】:2014-05-28 18:33:33
【问题描述】:
我使用 spring 3.2、spring security 3.1 和自定义身份验证器。
我的 security-context.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
<sec:http use-expressions="true">
<sec:form-login
login-page="/login.html"
default-target-url="/index.html"
always-use-default-target='true'
authentication-failure-url="/login-error.html"
/>
<sec:logout
logout-url="/j_spring_security_logout"
invalidate-session="true"
logout-success-url="/login.html"
/>
<sec:intercept-url pattern="/**" access="hasRole('ROLE_USER')" requires-channel="any"/>
<sec:http-basic />
</sec:http>
<sec:authentication-manager>
<sec:jdbc-user-service data-source-ref="dataSource"/>
<sec:authentication-provider ref="customAuthenticationProvider" />
</sec:authentication-manager>
<bean class="org.springframework.security.authentication.dao.DaoAuthenticationProvider" id="daoAuthenticationProvider">
<property name="userDetailsService" ref="authService"/>
<property name="passwordEncoder" ref="passwordEncoder"/>
</bean>
<bean class="com.test.UserDetailsServiceImpl" id="authService">
<property name="passwordEncoder" ref="passwordEncoder"/>
</bean>
<bean class="com.test.services.util.Encoder" id="passwordEncoder"/>
我得到这个错误:
Error creating bean with name 'userDetailsService' defined in class path resource [config/security-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
我的实现类
@Service("userDetailsService")
public class UserDetailsServiceImpl extends JdbcDaoImpl implements UserDetailsService {
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
...
}
}
我也有,但是如果我们检查我之前的错误,似乎看不到这段代码。
@Configuration
@EnableTransactionManagement
public class DBConfiguration {
@Bean(name = "dataSource")
public BasicDataSource dataSource() {
...
}
}
有什么想法吗?
【问题讨论】:
-
UserDetailsServiceImpl扩展了什么类? -
她扩展了 JdbcDaoImpl
-
为什么你在那个类上有
@Service("userDetailsService"),而且还要在你的xml配置中用id="authService"创建它? -
我相信您需要稍微清理一下您的代码,或者更详细地解释您正在尝试做什么。你有一个
UserDetailsServiceImpl,但你也在定义jdbc-user-service。这些在我看来是多余的。 -
我试过没有
得到同样的错误