I was curious of there was a way for me to run a repository impl containing autowired candidates, with an application main() (for testing purposes).
i know the problem is that the repo class containing the main isn't being wired in the main() method, which is causing none of the autowired candidates to be wired but I'm having trouble finding the syntax to make this happen.
The sample code snippet is below, as well as comments in the section where I'm encountering the issue
@Repository
@Transactional
public class RepositoryImpl implements Repository {
@Autowired
JdbcTemplate jdbcTemplate;
String query = "some query"
@Override
public boolean runQuery() {
Object[] params = {param1, param2};
boolean result = jdbcTemplate.queryForObject(query , params, Integer.class) == 1;
return result;
}
//included just for testing purposes
public static void main(String[] args) {
/*this is where i would like to run runQuery() to see a sample output
* something like this:
* repositoryImpl = new RepositoryImpl();
* syso(repositoryImpl.runQuery());
*/
}
}
I run into a null pointer which is coming from jdbc template not being wired properly. Could someone direct me as to how to autowire a class with a self contained application main()?
Is this even possible?
Thanks for your help!