My Spring Boot application is configured entirely using annotations (no XML context file). The root class looks like this:
package uk.org.sehicl.website;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import uk.org.sehicl.website.users.EmailSender;
import uk.org.sehicl.website.users.UserDatastore;
import uk.org.sehicl.website.users.UserManager;
import uk.org.sehicl.website.users.impl.RedisDatastore;
import uk.org.sehicl.website.users.impl.SendgridSender;
@SpringBootApplication
public class Application
{
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
@Bean
public UserDatastore userDatastore()
{
return new RedisDatastore(System.getenv("REDIS_URL"));
}
@Bean
public EmailSender emailSender()
{
return new SendgridSender();
}
@Bean
public UserManager userManager()
{
return new UserManager();
}
}
The UserManager
bean contains @Autowired
dependencies on the other two:
@Autowired
private UserDatastore datastore;
@Autowired
private EmailSender emailer;
When I run the application, everything starts up fine; but the datastore
and emailer
fields of the UserManager
bean are null
.
I'm sure I must be missing something really obvious, but how do I get these autowired dependencies to be, erm, autowired?