@SpringBootApplication
public class MainApplication {
@Autowired
static BibliographyIndexer bi;
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
bi.reindex();
}
}
@Repository
public class BibliographyIndexer {
...
}
Whenever I access the properties of bi
I get a NullPointerException
. I know the @Autowired
notation didn't work. But why?
Note: both classes are under the same package.
Additional question: Since I want to run a method upon the start of the spring application. Is this the best approach since @pepevalbe's answer already gave me the workaround I needed. Is there another way to run a method upon the start of the spring application?