List of usage examples for org.springframework.context ConfigurableApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:de.htw_berlin.f4.ai.kbe.kurznachrichten.app.App.java
public static void main(String[] args) { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); ShortMessageService sms = (ShortMessageService) context.getBean("ShortMessageService"); sms.createUser("hans", "leibzisch"); System.out.println("User hans created"); // sms.createUser("peter", "dresdn"); sms.createTopic("hans", "pegida"); long id = sms.createMessage("hans", "testnachricht am Ursprung", "pegida"); long respID = sms.respondToMessage("hans", "rumstehn tut der da glaube ich", id); // System.out.println(sms.getUsers()); // System.out.println(sms.getTopics()); System.out.println("Message by Topic Pegida:"); System.out.println("\t" + sms.getMessageByTopic("pegida", null).get(0).get(0).getContent()); try {/*w w w . jav a 2 s . c o m*/ System.out.println("Delete message"); sms.deleteMessage("hans", id); } catch (AuthorizationException e) { e.printStackTrace(); } // EntityManager em = EntityManagerFactory.getInstance().getEntitymanager(); // // createMessage(em); // printAllMessages(em); }
From source file:com.hmsinc.epicenter.tools.ToolLauncher.java
/** * @param args// w ww. jav a 2 s . co m */ public static void main(String[] args) { if (args.length > 0) { final String app = args[0]; final ConfigurableApplicationContext appContext = new ClassPathXmlApplicationContext( "classpath:" + app + "-util.xml"); final RunnableTool tool = (RunnableTool) appContext.getBean(app); Validate.notNull(tool, "Could not start tool: " + app); tool.setArguments(args); tool.run(); } }
From source file:com.autodomum.example.Example1.java
public static void main(String[] args) throws Exception { final ConfigurableApplicationContext context = SpringApplication.run(Example1.class, args); final JsonLampDao jsonLampDao = context.getBean(JsonLampDao.class); final EventComponent eventComponent = context.getBean(EventComponent.class); final EventContext eventContext = context.getBean(EventContext.class); final TelldusComponent telldusComponent = context.getBean(TelldusComponent.class); final NashornScriptComponent nashornScriptComponent = context.getBean(NashornScriptComponent.class); final Thread eventComponentThread = new Thread(eventComponent); eventComponentThread.setDaemon(true); eventComponentThread.setPriority(Thread.MIN_PRIORITY); eventComponentThread.setName("EventComponent"); eventComponentThread.start();//w w w.j a v a 2 s.com // Coordinates of Stockholm eventContext.setCoordinate(new Coordinate(18.063240d, 59.334591d)); eventComponent.updateEventContext(); eventComponent.register(LampStateChangedEvent.class, telldusComponent); final Thread telldusComponentThread = new Thread(telldusComponent); telldusComponentThread.setDaemon(true); telldusComponentThread.setPriority(Thread.MIN_PRIORITY); telldusComponentThread.setName("Telldus"); telldusComponentThread.start(); try (InputStream inputStream = Example1.class.getResourceAsStream("/lamps.json")) { jsonLampDao.load(inputStream); } try (InputStream inputStream = Example1.class.getResourceAsStream("/ai.js")) { nashornScriptComponent.replaceScript(inputStream); } }
From source file:org.s1p.app2.S1pKafkaApplication.java
public static void main(String[] args) throws Exception { ConfigurableApplicationContext context = new SpringApplicationBuilder(S1pKafkaApplication.class).web(false) .run(args);// w w w .j av a 2s . co m TestBean testBean = context.getBean(TestBean.class); testBean.send("foo"); context.getBean(Listener.class).latch.await(60, TimeUnit.SECONDS); context.close(); }
From source file:org.s1p.app5.S1pKafkaApplication.java
public static void main(String[] args) throws Exception { ConfigurableApplicationContext context = new SpringApplicationBuilder(S1pKafkaApplication.class).web(false) .run(args);/*from w w w . j av a 2 s .c om*/ TestBean testBean = context.getBean(TestBean.class); testBean.send(new Foo("foo", "bar")); context.getBean(Listener.class).latch.await(60, TimeUnit.SECONDS); context.close(); }
From source file:com.oreilly.springdata.rest.client.ProductsClient.java
public static void main(String[] args) { // Bootstrap RestOperations instance using Spring ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ClientConfiguration.class); context.registerShutdownHook();//from w w w . j a v a 2s . c om RestOperations operations = context.getBean(RestOperations.class); // Access root resource ResourceSupport root = operations.getForObject(ClientConfiguration.BASE_URL, Resource.class); Link productLink = root.getLink(ClientConfiguration.PRODUCTS_REL); // Follow link to access products Products products = operations.getForObject(productLink.getHref(), Products.class); System.out.println(products.getContent().iterator().next()); }
From source file:org.s1p.app3.S1pKafkaApplication.java
public static void main(String[] args) throws Exception { ConfigurableApplicationContext context = new SpringApplicationBuilder(S1pKafkaApplication.class).web(false) .run(args);/*from w ww .j ava2s . com*/ TestBean testBean = context.getBean(TestBean.class); for (int i = 0; i < 10; i++) { testBean.send("foo"); } context.getBean(Listener.class).latch.await(60, TimeUnit.SECONDS); context.close(); }
From source file:org.s1p.app7.S1pKafkaApplication.java
public static void main(String[] args) throws Exception { ConfigurableApplicationContext context = new SpringApplicationBuilder(S1pKafkaApplication.class).web(false) .run(args);/*from ww w .j av a 2s. com*/ TestBean testBean = context.getBean(TestBean.class); testBean.send("foo"); testBean.send("bar"); testBean.send("baz"); context.getBean(Listener.class).latch.await(60, TimeUnit.SECONDS); context.close(); }
From source file:org.s1p.app6.S1pKafkaApplication.java
public static void main(String[] args) throws Exception { ConfigurableApplicationContext context = new SpringApplicationBuilder(S1pKafkaApplication.class).web(false) .run(args);/*from ww w .j a va2s .c o m*/ TestBean testBean = context.getBean(TestBean.class); testBean.send(new GenericMessage<>(new Foo("foo", "bar"))); context.getBean(Listener.class).latch.await(60, TimeUnit.SECONDS); context.close(); }
From source file:com.oreilly.springdata.rest.client.CustomerClient.java
public static void main(String[] args) { // Setup RestTemplate though Spring ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ClientConfiguration.class); context.registerShutdownHook();//from www.j a v a 2s. c om RestOperations restOperations = context.getBean(RestOperations.class); // Access root resource ResourceSupport result = restOperations.getForObject(ClientConfiguration.BASE_URL, Resource.class); Link link = result.getLink(ClientConfiguration.CUSTOMERS_REL); System.out.println("Following: " + link.getHref()); // Follow link relation for customers to access those Customers customers = restOperations.getForObject(link.getHref(), Customers.class); for (Customer dto : customers) { com.oreilly.springdata.rest.core.Customer customer = dto.getContent(); System.out.println(customer.getFirstname() + " " + customer.getLastname()); } }