本文整理汇总了Java中org.springframework.context.support.AbstractApplicationContext.getBean方法的典型用法代码示例。如果您正苦于以下问题:Java AbstractApplicationContext.getBean方法的具体用法?Java AbstractApplicationContext.getBean怎么用?Java AbstractApplicationContext.getBean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.context.support.AbstractApplicationContext
的用法示例。
在下文中一共展示了AbstractApplicationContext.getBean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
public static void main (String [] args)
{
@SuppressWarnings({ "resource"})
AbstractApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
PumpEngine engine = (PumpEngine)context.getBean(PumpEngine.class);
engine.setArgs(args);
try {
engine.startPump();
} catch (Exception e) {
logger.error("Exception Occured while doing buy/sell transaction", e);
}
System.out.println("\n\n\nHope you will make a profit in this pump ;)");
System.out.println("if you could make a proit using this app please conside doing some donation with 1$ or 2$ to BTC address 1PfnwEdmU3Ki9htakiv4tciPXzo49RRkai \nit will help us doing more features in the future");
}
示例2: getApplicationContext
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
/**
* Provides a static, single instance of the application context. This method can be
* called repeatedly.
* <p/>
* If the configuration requested differs from one used previously, then the previously-created
* context is shut down.
*
* @return Returns an application context for the given configuration
*/
public synchronized static ConfigurableApplicationContext getApplicationContext(ServletContext servletContext, String[] configLocations)
{
AbstractApplicationContext ctx = (AbstractApplicationContext)BaseApplicationContextHelper.getApplicationContext(configLocations);
CmisServiceFactory factory = (CmisServiceFactory)ctx.getBean("CMISServiceFactory");
DefaultListableBeanFactory dlbf = new DefaultListableBeanFactory(ctx.getBeanFactory());
GenericWebApplicationContext gwac = new GenericWebApplicationContext(dlbf);
servletContext.setAttribute(GenericWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, gwac);
servletContext.setAttribute(CmisRepositoryContextListener.SERVICES_FACTORY, factory);
gwac.setServletContext(servletContext);
gwac.refresh();
return gwac;
}
示例3: getEventFiringWebDriver
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
/**
* This method makes an event firing instance of {@link org.openqa.selenium.WebDriver}
*
* @param driver an original instance of {@link org.openqa.selenium.WebDriver} that is
* supposed to be listenable
* @param listeners is a collection of {@link Listener} that
* is supposed to be used for the event firing
* @param <T> T
* @return an instance of {@link org.openqa.selenium.WebDriver} that fires events
*/
@SuppressWarnings("unchecked")
public static <T extends WebDriver> T getEventFiringWebDriver(T driver, Collection<Listener> listeners) {
List<Listener> listenerList = new ArrayList<>();
Iterator<Listener> providers = ServiceLoader.load(
Listener.class).iterator();
while (providers.hasNext()) {
listenerList.add(providers.next());
}
listenerList.addAll(listeners);
AbstractApplicationContext context = new AnnotationConfigApplicationContext(
DefaultBeanConfiguration.class);
return (T) context.getBean(
DefaultBeanConfiguration.WEB_DRIVER_BEAN, driver, listenerList, context);
}
示例4: main
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
public static void main(final String[] args) {
System.out.println("Notice this client requires that the CamelServer is already running!");
AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client-remoting.xml");
// just get the proxy to the service and we as the client can use the "proxy" as it was
// a local object we are invoking. Camel will under the covers do the remote communication
// to the remote ActiveMQ server and fetch the response.
Multiplier multiplier = context.getBean("multiplierProxy", Multiplier.class);
System.out.println("Invoking the multiply with 33");
int response = multiplier.multiply(33);
System.out.println("... the result is: " + response);
// we're done so let's properly close the application context
IOHelper.close(context);
}
示例5: main
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
System.out.println("Notice this client requires that the CamelServer is already running!");
AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
// get the camel template for Spring template style sending of messages (= producer)
ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);
System.out.println("Invoking the multiply with 22");
// as opposed to the CamelClientRemoting example we need to define the service URI in this java code
int response = (Integer)camelTemplate.sendBody("jms:queue:numbers", ExchangePattern.InOut, 22);
System.out.println("... the result is: " + response);
// we're done so let's properly close the application context
IOHelper.close(context);
}
示例6: main
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-file-client.xml");
// get the camel template for Spring template style sending of messages (= producer)
final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class);
// now send a lot of messages
System.out.println("Writing files ...");
for (int i = 0; i < SIZE; i++) {
producer.sendBodyAndHeader("file:target//inbox", "File " + i, Exchange.FILE_NAME, i + ".txt");
}
System.out.println("... Wrote " + SIZE + " files");
// we're done so let's properly close the application context
IOHelper.close(context);
}
示例7: main
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {
AbstractApplicationContext ctx=new ClassPathXmlApplicationContext("com/app/annotation_config/config.xml");
Object ob=ctx.getBean("Annotation");
model mod=(model)ob;
System.out.println("\t\t"+mod);
ctx.registerShutdownHook();
}
开发者ID:pratikdimble,项目名称:Spring_Life_Cycle_Init_Destroy_Using_Annotation,代码行数:8,代码来源:test_Annotation_Configure.java
示例8: main
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
public static void main(String args[])
{
AbstractApplicationContext ctx=new ClassPathXmlApplicationContext("com/app/xml_config/config.xml");
Object ob=ctx.getBean("model");
model_spring_bean mod=(model_spring_bean)ob;
System.out.println("\t\t"+mod);
ctx.registerShutdownHook();
}
示例9: main
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
System.out.println("Notice this client requires that the CamelServer is already running!");
AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
CamelContext camel = context.getBean("camel-client", CamelContext.class);
// get the endpoint from the camel context
Endpoint endpoint = camel.getEndpoint("jms:queue:numbers");
// create the exchange used for the communication
// we use the in out pattern for a synchronized exchange where we expect a response
Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
// set the input on the in body
// must be correct type to match the expected type of an Integer object
exchange.getIn().setBody(11);
// to send the exchange we need an producer to do it for us
Producer producer = endpoint.createProducer();
// start the producer so it can operate
producer.start();
// let the producer process the exchange where it does all the work in this oneline of code
System.out.println("Invoking the multiply with 11");
producer.process(exchange);
// get the response from the out body and cast it to an integer
int response = exchange.getOut().getBody(Integer.class);
System.out.println("... the result is: " + response);
// stopping the JMS producer has the side effect of the "ReplyTo Queue" being properly
// closed, making this client not to try any further reads for the replies from the server
producer.stop();
// we're done so let's properly close the application context
IOHelper.close(context);
}
示例10: main
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
System.out.println("Notice this client requires that the CamelServer is already running!");
AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
// get the camel template for Spring template style sending of messages (= producer)
final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class);
// now send a lot of messages
System.out.println("Sending ...");
final CountDownLatch latch = new CountDownLatch(POOL);
ExecutorService executors = Executors.newFixedThreadPool(POOL);
for (int i = 0; i < POOL; i++) {
final Integer idx = i;
executors.execute(new Runnable() {
public void run() {
try {
for (int j = 0; j < SIZE / POOL; j++) {
producer.sendBody("jms:queue:inbox", "Message " + idx.intValue() * j + j);
}
} finally {
latch.countDown();
}
}
});
}
latch.await(300, TimeUnit.SECONDS);
System.out.println("... Send " + SIZE + " message to JMS broker");
executors.shutdownNow();
// we're done so let's properly close the application context
IOHelper.close(context);
}
示例11: testStreamCaching
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
public void testStreamCaching() throws Exception {
AbstractApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {"org/apache/camel/spring/streamCaching.xml"});
CamelContext camelContext = appContext.getBean("camelContext", CamelContext.class);
assertFalse("StreamCaching should not be enabled", camelContext.isStreamCaching());
// we're done so let's properly close the application context
IOHelper.close(appContext);
}
示例12: testCamelProxyUsingRef
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
public void testCamelProxyUsingRef() throws Exception {
AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelProxyUsingRefTest.xml");
MyProxySender sender = ac.getBean("myProxySender", MyProxySender.class);
String reply = sender.hello("World");
assertEquals("Hello World", reply);
// we're done so let's properly close the application context
IOHelper.close(ac);
}
示例13: testAnotherCamelProxy
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
public void testAnotherCamelProxy() throws Exception {
// START SNIPPET: e1
AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/AnotherCamelProxyTest.xml");
MyProxySender sender = ac.getBean("myProxySender", MyProxySender.class);
String reply = sender.hello("Camel");
assertEquals("Bye Camel", reply);
// we're done so let's properly close the application context
IOHelper.close(ac);
// END SNIPPET: e1
}
示例14: testUsingRouteBuilderRefInCamelXml
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
public void testUsingRouteBuilderRefInCamelXml() throws Exception {
AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/routeBuilderRef.xml");
CamelContext context = applicationContext.getBean("camel5", CamelContext.class);
assertValidContext(context);
// we're done so let's properly close the application context
IOHelper.close(applicationContext);
}
示例15: testCamelProxy
import org.springframework.context.support.AbstractApplicationContext; //导入方法依赖的package包/类
public void testCamelProxy() throws Exception {
AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelProxyTest.xml");
MyProxySender sender = ac.getBean("myProxySender", MyProxySender.class);
String reply = sender.hello("World");
assertEquals("Hello World", reply);
// test sending inOnly message
MyProxySender anotherSender = ac.getBean("myAnotherProxySender", MyProxySender.class);
SpringCamelContext context = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();
MockEndpoint result = resolveMandatoryEndpoint(context, "mock:result", MockEndpoint.class);
result.expectedBodiesReceived("Hello my friends!");
anotherSender.greeting("Hello my friends!");
result.assertIsSatisfied();
result.reset();
// test sending inOnly message with other sender
MyProxySender myProxySenderWithCamelContextId = ac.getBean("myProxySenderWithCamelContextId", MyProxySender.class);
result.expectedBodiesReceived("Hello my friends again!");
myProxySenderWithCamelContextId.greeting("Hello my friends again!");
result.assertIsSatisfied();
// we're done so let's properly close the application context
IOHelper.close(ac);
}