私はjpa repositroyを拡張している以下のリポジトリを持っていますが、これをautowiredした実装クラスもあります。スタンドアロンアプリケーションのリポジトリメソッドを呼び出す方法は?
は@Repository
public interface ProjectDAO extends CrudRepository<Project, Integer> {}
@Service
public class ProjectServiceImpl {
@Autowired private ProjectDAO pDAO;
public void save(Project p) { pDAO.save(p); } }
今私は1 Application.java class
Class Application{
public static void main(String..s){
// I need a way to call a method of repository
}
}
設定ファイル
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories
@PropertySource("file:/Users/abc/Documents/application.properties")
public class PersistenceContext {
@Autowired
Environment environment;
を持っているので、どのように我々は、私は、任意のWebベースのコントローラを使用していけない場合には、メインからこれを呼ぶのですか?
class Application {
public static void main(String[] s){
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(PersistenceContext.class);
ProjectDAO dao = applicationContext.getBean(ProjectDAO.class);
}
}
編集:
、どこで、あなたの春のconfigがありますか? – StanislavL