Spring boot Autowired not working in Configuration class

One of the reason for this error is as you do not have implementation of this class. Create a class called CustomUserDetailsService implementing UserDetailsService and annotate it with @Component. Refer to spring documentation for more. or follow the solution cited by @reos


@Import is to add a configuration class into another configuration class.

http://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/reference/html/ch04s03.html

@ComponentScan is to scan for components declared in your code, like @Service, @Component, @Repository, among others.

http://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/reference/html/ch06s02.html

I think you need to add in your configuration class the @ComponentScan so it can scan the package with your component classes.

@Configuration
@ComponentScan(value = "org.foo.path.baseFolder")
public class MyConfiguration {
    @Autowired
    protected GlobalPropertiesLoader globalPropertiesLoader;

@Configurations are the classes, which will try to initiate first. Your GlobalPropertiesLoader doesn't have a instance of it, when MyConfiguration initiates. Try this.

@Configuration
@Import({GlobalPropertiesLoader.class})
public class MyConfiguration {
}