I'd like to do a simple main using Spring boot and have some fields autowired.
I'd like the app to fail (error-code != 0) if some exception is thrown in the process.
Example:
@SpringBootApplication
public class SqlInserterMain
{
@Autowired
private static JdbcTemplate jdbcTemplate;
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(SqlInserterMain.class, args);
insertData();
context.close();
}
private static void insertData()
{
// Do something with jdbcTemplate.
// If jdbcTemplate fails on exception, the app should fail and return some error code.
System.out.println("YOYO" + jdbcTemplate);
}
}
But, jdbcTemplate
is null.
If I add a @component
or an ApplicationRunner
, the @autowire
will work but I won't get the main to fail.
Any idea how to do a fast and simple main with some autowired fields that will fail on an exception? Thanks.