public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); context.registerShutdownHook(); Country country = context.getBean("country", Country.class); System.out.println(country.getCapital("india")); System.out.println(country.getCapital("spain")); }
/** * Runs the Jetty Embedded DTS Web Service. * * @throws Exception if the Server fails to start */ public void run() throws Exception { final AbstractApplicationContext ctx = new ClassPathXmlApplicationContext( new String[] { "/org/dataminx/dts/ws/application-context.xml", "/org/dataminx/dts/ws/embedded-jetty-context.xml" }); ctx.registerShutdownHook(); final Server server = (Server) ctx.getBean("jettyServer"); ServletContext servletContext = null; for (final Handler handler : server.getHandlers()) { if (handler instanceof Context) { final Context context = (Context) handler; servletContext = context.getServletContext(); } } final XmlWebApplicationContext wctx = new XmlWebApplicationContext(); wctx.setParent(ctx); wctx.setConfigLocation(""); wctx.setServletContext(servletContext); wctx.refresh(); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wctx); server.start(); }
public static void main(String[] args) { try (AbstractApplicationContext context = new AnnotationConfigApplicationContext(App.class)) { context.registerShutdownHook(); context.getBean(SignalEmitter.class).emit(); } }
@Override public boolean appStart(IScope app) { log.debug("Starting BigBlueButton version " + version); IContext context = app.getContext(); appCtx = (AbstractApplicationContext) context.getApplicationContext(); appCtx.addApplicationListener(new ShutdownHookListener()); appCtx.registerShutdownHook(); return super.appStart(app); }
public static void beanPostProcessorExample() { System.out.println("----beanPostProcessorExample----"); AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("com/wilson/testlab/spring/b/bean/beans2.xml"); HelloWorld singletonObjA = (HelloWorld) ctx.getBean("helloWorldCallback"); singletonObjA.getMessage(); ((AbstractApplicationContext) ctx).registerShutdownHook(); }
public static void main(String[] args) throws JMSException { ApplicationContext applicationContext = new ClassPathXmlApplicationContext(APPLICATION_CONTEXT_FILES); ((AbstractApplicationContext) applicationContext).registerShutdownHook(); ConnectionFactory factory = (ConnectionFactory) applicationContext.getBean("connectionFactory"); Connection con = factory.createConnection(); Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); con.close(); }
/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ApplicationContext context = new ClassPathXmlApplicationContext("SpringConfig.xml"); ((AbstractApplicationContext) context).registerShutdownHook(); Restaurant restaruantObj1 = (Restaurant) context.getBean("restaurantBean"); restaruantObj1.setWelcomeNote("Object1 is setting welcome note properrty"); restaruantObj1.greetCustomer(); Restaurant restaurantObj = (Restaurant) context.getBean("restaurantBean"); restaurantObj.greetCustomer(); }
public static void main(String[] args) { PropertyConfigurator.configure(System.getProperty("log4j.configuration")); AbstractApplicationContext context = new AnnotationConfigApplicationContext(NadronSpringConfig.class); // For the destroy method to work. context.registerShutdownHook(); // Start tcp and flash servers ServerManager manager = (ServerManager) context.getBean("serverManager"); try { manager.startServers(18090, 843, 18090); } catch (Exception e) { LOG.error("Could not start servers cleanly: {}", e); } }
public static void main(String[] args) { ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml"); Profile profile = (Profile) applicationContext.getBean("profile"); System.out.println(); profile.printName(); profile.printAge(); HelloWorld helloWorld = (HelloWorld) applicationContext.getBean("helloWorld"); helloWorld.getMessage(); ((AbstractApplicationContext) applicationContext).registerShutdownHook(); ((AbstractApplicationContext) applicationContext).close(); }
public static void main(String[] args) throws Exception { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "/META-INF/spring/pig-context-password-repository.xml", PigAppWithRepository.class); log.info("Pig Application Running"); context.registerShutdownHook(); String outputDir = "/data/password-repo/output"; FsShell fsShell = context.getBean(FsShell.class); if (fsShell.test(outputDir)) { fsShell.rmr(outputDir); } PasswordRepository repo = context.getBean(PigPasswordRepository.class); repo.processPasswordFile("/data/passwd/input"); /* Collection<String> files = new ArrayList<String>(); files.add("/data/passwd/input"); files.add("/data/passwd/input2"); repo.processPasswordFiles(files); */ }
/** * Load the Spring Integration Application Context * * @param args - command line arguments */ public static void main(final String... args) { LOGGER.info( "\n=========================================================" + "\n " + "\n Welcome to Spring Integration! " + "\n " + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + "\n " + "\n========================================================="); @SuppressWarnings("resource") final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/spring-integration-confirms-context.xml"); context.registerShutdownHook(); LOGGER.info( "\n=========================================================" + "\n " + "\n This is the AMQP Sample with confirms/returns - " + "\n " + "\n Please enter some text and press return. The entered " + "\n Message will be sent to the configured RabbitMQ Queue," + "\n then again immediately retrieved from the Message " + "\n Broker and ultimately printed to the command line. " + "\n Send 'fail' to demonstrate a return because the " + "\n message couldn't be routed to a queue. " + "\n Send 'nack' to demonstrate a NACK because the " + "\n exchange doesn't exist, causing the channel to be " + "\n closed in error by the broker. " + "\n " + "\n========================================================="); }
/** 应用初始化 */ public void initialize() { springContext = new ClassPathXmlApplicationContext(new String[] {"applicationContext*.xml"}); springContext.registerShutdownHook(); }
private static void startService() { AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); // context.start(); context.registerShutdownHook(); }
public static void main(String[] args) { System.out.println("Starting application context"); @SuppressWarnings("resource") AbstractApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class); ctx.registerShutdownHook(); }
public static void main(String[] args) { context = new ClassPathXmlApplicationContext("abc.xml"); context.registerShutdownHook(); Triangle triangle = (Triangle) context.getBean("triangle"); triangle.draw(); }
public static void main(String args[]) { try { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); // Define a bean and register it beanFactory.registerSingleton("args", Arrays.asList(args)); GenericApplicationContext cmdArgCxt = new GenericApplicationContext(beanFactory); // Must call refresh to initialize context cmdArgCxt.refresh(); String configs[] = {"/META-INF/spring/app-config.xml"}; AbstractApplicationContext context = new ClassPathXmlApplicationContext(configs, cmdArgCxt); context.registerShutdownHook(); Workflow workflow = (Workflow) context.getBean("workflow"); System.out.println("Workflow names:"); int i = 1; for (String name : workflow.getWorkflowNames()) { System.out.format("%02d) %s%n", i++, name); } BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("User: "******"caller", username); String command; do { try { System.out.print("Enter command: "); command = in.readLine(); if (command == null || "q".equals(command) || "quit".equals(command)) break; if ("log".equals(command)) { System.out.print("User: "******"caller", username); } if ("init".equals(command)) { System.out.print("Workflow name: "); String workflowName = in.readLine(); long id = workflow.initialize(workflowName, 1, inputs); System.out.println("Workflow initialized with id: " + id); } else if ("desc".equals(command)) { System.out.print("Workflow ID: "); long id = Long.parseLong(in.readLine()); String workflowName = workflow.getWorkflowName(id); WorkflowDescriptor descriptor = workflow.getWorkflowDescriptor(workflowName); System.out.print("Workflow state: "); switch (workflow.getEntryState(id)) { case WorkflowEntry.CREATED: System.out.println("CREATED"); break; case WorkflowEntry.ACTIVATED: System.out.println("ACTIVATED"); break; case WorkflowEntry.SUSPENDED: System.out.println("SUSPENDED"); break; case WorkflowEntry.KILLED: System.out.println("KILLED"); break; case WorkflowEntry.COMPLETED: System.out.println("COMPLETED"); break; default: System.out.println("UNKNOWN"); } List<Step> currentSteps = workflow.getCurrentSteps(id); System.out.println("Current steps:"); int j = 0; for (Step step : currentSteps) { ++j; StepDescriptor stepDesc = descriptor.getStep(step.getStepId()); System.out.println("Meta attributes:"); System.out.format("\t%s%n", stepDesc.getMetaAttributes().toString()); System.out.format( "%02d) %s (%s - %s)%n", step.getStepId(), stepDesc.getName(), step.getStatus(), step.getOwner()); } int[] availableActions = workflow.getAvailableActions(id, inputs); System.out.println("Available actions:"); for (j = 0; j < availableActions.length; j++) { ActionDescriptor action = descriptor.getAction(availableActions[j]); System.out.println(String.format("%02d) %s", availableActions[j], action.getName())); } } else if ("exec".equals(command)) { System.out.print("Workflow ID: "); long id = Long.parseLong(in.readLine()); System.out.print("Action ID: "); int actionId = Integer.parseInt(in.readLine()); workflow.doAction(id, actionId, inputs); } else if ("query".equals(command)) { Set<WorkflowNameAndStep> stepInfos = new LinkedHashSet<WorkflowNameAndStep>(); stepInfos.add(new WorkflowNameAndStep(1, "example")); stepInfos.add(new WorkflowNameAndStep(2, "sp3-moderation")); List ids = workflow.getWorkflowsByNamesAndSteps(stepInfos); System.out.println("Found ids are: " + ids); } } catch (Exception e) { e.printStackTrace(); } System.out.println("-------------------------------------"); } while (true); System.out.println("Exiting"); } catch (Exception e) { e.printStackTrace(); } }
public static <T> T getBeanFromContext( String nameOfBean, Class<T> requiredType, AbstractApplicationContext context) { T obj = context.getBean(nameOfBean, requiredType); context.registerShutdownHook(); return obj; }
@AfterClass public static void shutdownEnvironment() { ((AbstractApplicationContext) context).registerShutdownHook(); }