List of usage examples for org.springframework.context ApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:ro.pippo.demo.spring.SpringDemo2.java
public static void main(String[] args) { // create spring application context ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfiguration2.class); Application application = (Application) applicationContext.getBean("application"); Pippo pippo = new Pippo(application); pippo.start();//from w w w.ja va 2s . c o m }
From source file:com.apress.prospringintegration.corespring.iocbasics.BasicIoCMain.java
public static void main(String[] args) { ApplicationContext app = new ClassPathXmlApplicationContext("ioc_basics.xml"); BasicPOJO basicPOJO = (BasicPOJO) app.getBean("basic-pojo"); assert basicPOJO != null; System.out.println(basicPOJO.getColor()); ColorEnum colorEnum = (ColorEnum) app.getBean("randomColor"); System.out.println("randomColor: " + colorEnum); colorEnum = (ColorEnum) app.getBean("exclusiveColor"); System.out.println("exclusiveColor: " + colorEnum); ColorPicker colorPicker = (ColorPicker) app.getBean(ColorPicker.class); assert colorPicker != null; System.out.println(colorPicker.getColorRandomizer().randomColor()); BasicIoCMain.demonstrateScopes(app); // Custom Scope Registration with SimpleThreadScope ConfigurableApplicationContext configApp = (ConfigurableApplicationContext) app; configApp.getBeanFactory().registerScope("thread", new SimpleThreadScope()); }
From source file:uta.ak.ExecQuartzJob.java
public static void main(String[] args) throws Exception { SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); ApplicationContext applicationContext = new ClassPathXmlApplicationContext("quartzContext.xml"); Scheduler quartzScheduler = (Scheduler) applicationContext.getBean("quartzScheduler"); JobDetail jobDetail = JobBuilder.newJob(CollectTwitterJob.class) .withIdentity("qrtz_job_collecttwitter", "qrtz_job_collecttwitter").build(); SimpleScheduleBuilder builder = SimpleScheduleBuilder.simpleSchedule().repeatSecondlyForTotalCount(1000) .withIntervalInHours(24);// ww w. j a v a 2 s . c o m Trigger trigger = TriggerBuilder.newTrigger() .withIdentity("qrtz_trigger_collecttwitter", "qrtz_trigger_collecttwitter") .startAt(format1.parse("2016-08-03 00:05:00")).withSchedule(builder).build(); // quartzScheduler.scheduleJob(jobDetail, trigger); }
From source file:com.spring.tutorial.configuration.beansconfig.hybrid.App.java
public static void main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext( "com/spring/tutorial/configuration/beansconfig/hybrid/applicationContext.xml"); Foo foo = ctx.getBean(Foo.class); Bar bar = ctx.getBean(Bar.class); ((ClassPathXmlApplicationContext) ctx).close(); }
From source file:fi.vrk.xroad.catalog.collector.XRoadCatalogCollector.java
public static void main(String[] args) throws Exception { ApplicationContext context = SpringApplication.run(XRoadCatalogCollector.class, args); ActorSystem system = context.getBean(ActorSystem.class); final LoggingAdapter log = Logging.getLogger(system, "Application"); Long collectorInterval = (Long) context.getBean("getCollectorInterval"); log.info("Starting up catalog collector with collector interval of {}", collectorInterval); SpringExtension ext = context.getBean(SpringExtension.class); // Use the Spring Extension to create props for a named actor bean ActorRef supervisor = system.actorOf(ext.props("supervisor")); system.scheduler().schedule(Duration.Zero(), Duration.create(collectorInterval, TimeUnit.MINUTES), supervisor, Supervisor.START_COLLECTING, system.dispatcher(), null); }
From source file:pl.edu.amu.wmi.bank.Bank.java
public static void main(String[] args) throws InterruptedException, IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); ApplicationContext context = new ClassPathXmlApplicationContext("Context.xml"); SendPublicKeyService keySender = (SendPublicKeyService) context.getBean("sendPublicKeyToShopService"); keySender.sendPublicKey();/*from w ww . j av a2s.co m*/ Accounts accounts = (Accounts) context.getBean("accounts"); System.out.println(accounts); while (true) { System.out.println("Wcisnij cokolwiek zeby ponownie wyslac klucz"); reader.readLine(); keySender.sendPublicKey(); } }
From source file:com.mkyong.AppJobAllExport.java
/** * @param args the command line arguments *///from ww w . j av a 2 s . c om public static void main(String[] args) { fLogger.log(Level.INFO, "Export all csv to mysql"); String[] springConfig = { "spring/batch/config/database.xml", "spring/batch/config/context.xml", "spring/batch/jobs/csvexport/job-all-export.xml" }; ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("exportJob"); try { JobExecution execution = jobLauncher.run(job, new JobParameters()); fLogger.log(Level.INFO, "Exit Status : {0}", execution.getStatus()); } catch (JobParametersInvalidException e) { e.getMessage(); } catch (JobExecutionAlreadyRunningException e) { e.getMessage(); } catch (JobInstanceAlreadyCompleteException e) { e.getMessage(); } catch (JobRestartException e) { e.getMessage(); } fLogger.log(Level.INFO, "Done"); }
From source file:com.mkyong.AppJobAllImport.java
/** * @param args the command line arguments *//*from w ww. jav a 2 s . c o m*/ public static void main(String[] args) { fLogger.log(Level.INFO, "Import all csv to mysql"); String[] springConfig = { "spring/batch/config/database.xml", "spring/batch/config/context.xml", "spring/batch/jobs/csvimport/job-all-import.xml" }; ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("importJob"); try { JobExecution execution = jobLauncher.run(job, new JobParameters()); fLogger.log(Level.INFO, "Exit Status : {0}", execution.getStatus()); } catch (JobParametersInvalidException e) { e.getMessage(); } catch (JobExecutionAlreadyRunningException e) { e.getMessage(); } catch (JobInstanceAlreadyCompleteException e) { e.getMessage(); } catch (JobRestartException e) { e.getMessage(); } fLogger.log(Level.INFO, "Done"); }
From source file:edu.pitt.sis.infsci2730.finalProject.dao.ZZTest.java
public static void main(String[] args) throws Exception { try {// w w w. jav a 2 s. co m ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); AddressDao dao = (AddressDao) ac.getBean("addressDao"); String[] a = { "Pittsburgh", "Fifth", "PA", "15213" }; // String[] b={"2","2","3","15"}; System.out.println(dao.addAddress(a)); // System.out.println(dao.InsertRecordByTransactionIDAndProductId(b)); // List<RecordDBModel> list=dao.GetRecordByTransactionID("1"); // for(RecordDBModel r:list){ // System.out.println("GetRecordByTransactionID "+r.getProduct_id()); // } // // List<RecordDBModel> list2=dao.GetRecordByProductID("1"); // for(RecordDBModel r:list2){ // System.out.println("GetRecordByProductID "+r.getProduct_id()); // } // System.out.println("GetTransaction"); // SqlRowSet rows = dao.GetTransaction("5"); // while(rows.next()){ // System.out.println(rows.getInt(1)+" "+rows.getTimestamp(2)+" "+rows.getInt(4)); // } } catch (RuntimeException e) { e.printStackTrace(); } }
From source file:org.seasar.dao.spring.example.DepartmentDaoClient.java
public static void main(final String[] args) { final BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator.getInstance(); final BeanFactoryReference ref = locator.useBeanFactory("context"); final ApplicationContext context = (ApplicationContext) ref.getFactory(); try {/* w w w .j ava 2 s . co m*/ final DepartmentDao dao = (DepartmentDao) context.getBean("departmentDao"); final Department dept = new Department(); dept.setDeptno(99); dept.setDname("foo"); dao.insert(dept); dept.setDname("bar"); System.out.println("before update versionNo:" + dept.getVersionNo()); dao.update(dept); System.out.println("after update versionNo:" + dept.getVersionNo()); dao.delete(dept); } finally { ref.release(); } }