java - How to invoke repository method for standalone application? -


i have following repository extends jpa repositroy , have implementation class have autowired this.

@repository public interface projectdao extends crudrepository<project, integer> {}  @service public class projectserviceimpl {  @autowired private projectdao pdao;  public void save(project p) { pdao.save(p); } } 

now have 1 application.java class

class application{ public static void main(string..s){ // need way call method of repository } } 

configuration file

@configuration @enabletransactionmanagement @enablejparepositories @propertysource("file:/users/abc/documents/application.properties") public class persistencecontext {     @autowired     environment environment; 

so how call main in case dont use web based controller?

this way:

class application {     public static void main(string[] s){         annotationconfigapplicationcontext applicationcontext = new annotationconfigapplicationcontext(persistencecontext.class);         projectdao dao = applicationcontext.getbean(projectdao.class);     } } 

edit:

class application {     public static void main(string[] s){         annotationconfigapplicationcontext applicationcontext = new annotationconfigapplicationcontext(persistencecontext.class);         projectserviceimpl service = applicationcontext.getbean(projectserviceimpl.class);     } } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -