I am a newbie and have been banding my head against this code for the past couple of days. I really like how the framework is laid out and works, but this one piece of code has been a stumbling block for me.
I am trying to implement a UserDetailsService, but for some reason the Authentication-Provider cannot find my service. The service is annotated as a service @Service("userDetailsService") and I have configured Spring to automatically find components using the "context:annotation-config" and "context:component-scan" tags in the servlet.xml config. I assumed that the service will be auto-magically loaded and that I would not have to make an explicit bean entry in any applicationContext.xml file, but...it doesn't seem to be working. I have tried all sorts of permeatations (and google searches), but nothing seems to work.
What am I doing wrong? I am using Security 3.0.2 and Spring 3.0.5. Below are snips of my class and my config files. Any help or pointers would be appreciated.
The error that I am getting is:
Caused by: org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'userDetailsService' is defined
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanDefinition(DefaultListab leBeanFactory.java:527)
at
.....
applicationContext-security.xml
UserDetailsServiceImpl.javaCode:..... <global-method-security pre-post-annotations="enabled"> </global-method-security> <http use-expressions="true" > <intercept-url pattern="/" access="permitAll"/> ..... </http> <beans:bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"> <beans:property name="userDetailsService" ref="userDetailsService"/> </beans:bean> <beans:bean id="authenticationManager" class="org.springframework.security.authentication.ProviderManager"> <beans:property name="providers"> <beans:list> <beans:ref local="daoAuthenticationProvider" /> </beans:list> </beans:property> </beans:bean> <authentication-manager> <authentication-provider user-service-ref="userDetailsService"> <password-encoder hash="md5"/> </authentication-provider> </authentication-manager> .....
web.xmlCode:package com.myapp.authentication; ..... @Service("userDetailsService") public class UserDetailsServiceImpl implements UserDetailsService { @Autowired private MemberDAO memberDAO; @Autowired private Assembler assembler; @Transactional(readOnly = true) public UserDetails loadUserByUsername(String username) ....
spring-servlet.xmlCode:..... <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> .....
[/CODE]Code:<beans xmlns="http://www.springframework.org/schema/beans"...... <context:annotation-config /> <context:component-scan base-package="com.myapp" /> </beans> .....
Thank,
Joe


Reply With Quote
