List of usage examples for org.springframework.context ApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:com.precioustech.fxtrading.tradingbot.FXTradingBot.java
@SuppressWarnings("resource") public static void main(String[] args) { if (args.length == 0) { LOG.fatal("Usage: FxTradingBot <Implementation Config FileName>"); System.exit(1);// www. j a v a 2s.c o m } ApplicationContext appContext = new ClassPathXmlApplicationContext("tradingbot-app.xml", args[0]); MarketDataStreamingService marketDataStreamingService = appContext .getBean(MarketDataStreamingService.class); marketDataStreamingService.startMarketDataStreaming(); EventsStreamingService eventStreamingService = appContext.getBean(EventsStreamingService.class); eventStreamingService.startEventsStreaming(); }
From source file:org.openscore.lang.tools.verifier.VerifierMain.java
public static void main(String[] args) { String repositoryPath = args[0]; Validate.notNull(repositoryPath, "You must pass a path to your repository"); repositoryPath = FilenameUtils.separatorsToSystem(repositoryPath); Validate.isTrue(new File(repositoryPath).isDirectory(), "Directory path argument \'" + repositoryPath + "\' does not lead to a directory"); ApplicationContext context = new AnnotationConfigApplicationContext(VerifierSpringConfiguration.class); SlangContentVerifier slangContentVerifier = context.getBean(SlangContentVerifier.class); try {// ww w . ja va2 s . c o m int numberOfValidSlangFiles = slangContentVerifier.verifyAllSlangFilesInDirAreValid(repositoryPath); System.out.println("SUCCESS: Found " + numberOfValidSlangFiles + " slang files under directory: \"" + repositoryPath + "\" and all are valid."); System.exit(0); } catch (Exception e) { System.out.println(e.getMessage() + "\n\nFAILURE: Validation of slang files under directory: \"" + repositoryPath + "\" failed."); // TODO - do we want to throw exception or exit with 1? System.exit(1); } }
From source file:siia.jms.MessageDrivenPojoDemo.java
public static void main(String[] args) { // start the context that contains the message-driven POJO ApplicationContext context = new ClassPathXmlApplicationContext("siia/jms/message-driven-pojo.xml"); // send a Message with JmsTemplate JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class); jmsTemplate.convertAndSend("siia.mdp.queue", "World"); }
From source file:org.cgiar.dapa.ccafs.tpe.geojson.MailTest.java
public static void main(String[] args) { // Create the application context ApplicationContext context = new FileSystemXmlApplicationContext("applicationContext.xml"); // Get the mailer instance ITPEMailService mailer = (ITPEMailService) context.getBean("mailService"); // Send a composed mail mailer.sendMail("ccafstpe@gmail.com", "Test Subject", "Testing body"); // Send a pre-configured mail mailer.sendPreConfiguredMail("Exception occurred."); }
From source file:sg.edu.ntu.hrms.test.SpringTest.java
/** * @param args the command line arguments *///from w w w.java 2s .com public static void main(String[] args) { // TODO code application logic here ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class); //appContext.register(AppConfig.class); LoginService login = (LoginService) ctx.getBean(LoginService.class); UserDTO auth = login.authenticate("derique", "pass"); if (auth != null) { System.out.println("auth success"); } else { System.out.println("auth failed"); } }
From source file:com.dangdang.ddframe.rdb.sharding.example.config.spring.masterslave.SpringNamespaceWithMasterSlaveMain.java
public static void main(final String[] args) throws SQLException { // CHECKSTYLE:ON ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "META-INF/applicationContextWithMasterSlave.xml"); OrderService orderService = applicationContext.getBean(OrderService.class); orderService.insert();//from www . j a va 2 s.c om orderService.select(); orderService.delete(); orderService.select(); }
From source file:org.seasar.dao.spring.example.EmployeeDaoClient.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 {/*from w w w.j a v a 2 s.c om*/ final EmployeeDao dao = (EmployeeDao) context.getBean("employeeDao"); final List employees = dao.getAllEmployees(); for (int i = 0; i < employees.size(); ++i) { System.out.println(employees.get(i)); } final Employee employee = dao.getEmployee(7788); System.out.println(employee); final int count = dao.getCount(); System.out.println("count:" + count); dao.getEmployeeByJobDeptno(null, null); dao.getEmployeeByJobDeptno("CLERK", null); dao.getEmployeeByJobDeptno(null, new Integer(20)); dao.getEmployeeByJobDeptno("CLERK", new Integer(20)); dao.getEmployeeByDeptno(new Integer(20)); dao.getEmployeeByDeptno(null); System.out.println("updatedRows:" + dao.update(employee)); } finally { ref.release(); } }
From source file:com.balla.activemq.pubsub.example.PubSubDriver.java
public static void main(String args[]) { ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "classpath:activemq-jms-spring-context.xml"); MessagePublisher messagePublisher = (MessagePublisher) applicationContext.getBean("messagePublisher"); messagePublisher.sendMessage("This is a message that will be posted into Topic Sagar."); }
From source file:com.dianping.dpsf.other.echo.EchoClient.java
/** * @param args//from w w w . ja v a2 s . co m * @throws Exception */ public static void main(String[] args) throws Exception { PigeonClientMock.setServiceAddress("127.0.0.1:20001,127.0.0.1:20002"); ApplicationContext ctx = new ClassPathXmlApplicationContext("echo-client.xml"); IEcho s = (IEcho) ctx.getBean("echo"); // System.out.println(s.echo("aa")); // Thread.sleep(3000); // System.out.println(s.echo("aa")); // System.out.println("firing"); Random rnd = new Random(System.currentTimeMillis()); List<String[]> hostList = new ArrayList<String[]>(); hostList.add(new String[] { "127.0.0.1", "20001", "1" }); PigeonClientMock.getSc().onServiceHostChange("http://service.dianping.com/echoService", hostList); int i = 0; while (i < 100) { try { System.out.println(s.echo("aa")); } catch (Exception e) { System.out.println("EEEEEEEEEEEEEEEEEEEEEEE"); } Thread.sleep(2000); if (i == 1) { System.out.println("+++++++++++++++++++adding 20002++++++++++++++++"); hostList = new ArrayList<String[]>(); hostList.add(new String[] { "127.0.0.1", "20001", "1" }); hostList.add(new String[] { "127.0.0.1", "20002", "1" }); PigeonClientMock.getSc().onServiceHostChange("http://service.dianping.com/echoService", hostList); } if (i == 5) { System.out.println("+++++++++++++++++++adding 20003++++++++++++++++"); hostList = new ArrayList<String[]>(); hostList.add(new String[] { "127.0.0.1", "20001", "1" }); hostList.add(new String[] { "192.168.32.111", "20003", "1" }); PigeonClientMock.getSc().onServiceHostChange("http://service.dianping.com/echoService", hostList); } if (i == 10) { System.out.println("--------------------change wt------------"); PigeonClientMock.getSc().onHostWeightChange("127.0.0.1", 2); } i++; } }
From source file:com.softserveinc.internetbanking.testit.JDBCtemplateAccount.java
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml"); AccountJDBCTemplate accountJDBCTemplate = (AccountJDBCTemplate) context.getBean("accountJDBCTemplate"); // /*from ww w.ja v a2s. c om*/ // System.out.println("------Records Creation--------" ); // BigDecimal number = new BigDecimal("200.00"); // accountJDBCTemplate.createAccount("NEW", "Valex Obama", number); // accountJDBCTemplate.createAccount("NEW", "Ralex Obama", number); // System.out.println("------Listing Multiple Records--------" ); // List<Account> accounts = accountJDBCTemplate.listAccounts(); // for (Account record : accounts) { // System.out.print("ID : " + record.getAccount_id() ); // System.out.print(", Status : " + record.getStatus()); // System.out.println(", Owner Name : " + record.getOwnerName()); // System.out.println(", Account Amount : " + record.getAccountAmount()); // } // System.out.println("----Updating Record with ID = 4 -----" ); // accountJDBCTemplate.updateStatus(4, "ACTIVE"); // System.out.println("----Listing Record with ID = 1 -----"); Account account = accountJDBCTemplate.getAccount(1); System.out.print("ID : " + account.getAccount_id()); System.out.print(", Name : " + account.getOwnerName()); System.out.println("username " + accountJDBCTemplate.getAccountByUsername("lex").getOwnerName()); }