In my business application I am using
the following application stack:
- MySQL <> Hibernate <> Spring Data JPA (using JpaRepository interfaces)
- Spring Framework (3.2.2) <> Apache Tiles + Thymeleaf
Before trying the new javaconfig implementations,
I have a working business application (as follows) using spring-security.xml.
Furthermore based on the entities / models from database (User, Role, Auth)
and repositories (JpaRepository from spring-data-jpa) only as interfaces,
I have implemented a custom UserDetailsService and AuthenticationProvider,
in which the repositories of the User model is getting @Inject-ed (and some more).
Thus for configurating these, I provided them as beans:
@Bean
public AuthenticationProvider usernamePasswordAuthenticationProvider() {
UsernamePasswordAuthenticationProvider authProv = new UsernamePasswordAuthenticationProvider();
return authProv;
}
@Bean(name = "userDetailsService")
public UserDetailsService passwordUserDetailsService() {
return new PasswordUserDetailsService();
}
Like in some of your examples, I configured these in a similar way:
protected AuthenticationManager authenticationManager(
AuthenticationBuilder authenticationRegistry) throws Exception {
return authenticationRegistry
.add(usernamePasswordAuthenticationProvider())
.userDetails(passwordUserDetailsService()).and()
.build();
}
So far so good, I think the other config is not important at the moment. When I try to start my tomcat server (in eclipse), I noticed in the logs that spring-data-jpa created the required beans, e.g.:
DefaultListableBeanFactory - Overriding bean definition for bean 'userRepository': replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; ...
The next initialized beans are about my beans from java configuration (mvc, view, persistence), e.g.:
AnnotationConfigWebApplicationContext - Bean 'dataSourceConfig' of type [class ...]
After the latter initialization usually the xml from spring security is read and beans are created. In case of the java config of spring security (the test problem now), it is complaining that it cannot inject the upper mentioned userRepository, though working in xml mode. The complete exception chain is listed here:
http://pastebin.com/KK9wXR46
Do you have any idea what the problem could be ?
I thought, maybe your java config is intitializing too early,
that my userRepository bean could not be found (though working in xml mode).