I've been trying to make spring scan for beans and components inside the startup class itself to no avail. Here's my startup class:
@SpringBootApplication
@EnableAsync
@Configuration
@EnableAutoConfiguration
public class CastleApplication{
@Autowired
BalanceInfoDAO balanceInfoDAO;
public static void main(String[] args) {
SpringApplication.run(CastleDaoApplication.class, args);
new CastleApplication().printBalance("XXXXXXXX");
}
void printBalance(String number) {
float monthlyAmount = this.balanceInfoDAO.getMonthlyAmount(msisdn);
System.out.println(monthlyAmount);
}
}
When I run the application, the ivar balanceInfoDAO
is null. There is a class implementing the BalanceInfoDao interface which is annotated with @Service and it's under the same base package as startup class. So what do I have to do to make spring inject the dependency inside the startup class itself?