本文整理汇总了Java中org.springframework.context.support.AbstractApplicationContext类的典型用法代码示例。如果您正苦于以下问题:Java AbstractApplicationContext类的具体用法?Java AbstractApplicationContext怎么用?Java AbstractApplicationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractApplicationContext类属于org.springframework.context.support包,在下文中一共展示了AbstractApplicationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.springframework.context.support.AbstractApplicationContext; //导入依赖的package包/类
public void init() {
//启动并设置Spring
AbstractApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
ctx.registerShutdownHook();
NContext.setApplicationContext(ctx);
//初始化房间管理器
HomeManager homeManager = HomeManager.getInstance();
homeManager.init();
//初始化用户管理器
PlayerManager playerManager = PlayerManager.getInstance();
playerManager.init();
//初始化Gateway
ClientManager clientManager = ClientManager.getInstance();
clientManager.init();
//启动异步处理器
AsyncProcessor asyncProcessor = AsyncProcessor.getInstance();
asyncProcessor.start();
//启动滴答服务
TickerService tickerService = TickerService.getInstance();
tickerService.start();
}
示例2: configureMessageSource
import org.springframework.context.support.AbstractApplicationContext; //导入依赖的package包/类
/**
* 配置基于配置的MessageSource
*/
private void configureMessageSource() {
// MessageSource bean name
String messageSourceBeanName = AbstractApplicationContext.MESSAGE_SOURCE_BEAN_NAME;
// Config MessageSource bean name
String configMessageSourceBeanName = CONFIG_MESSAGE_SOURCE_BEAN_NAME;
// 基于配置服务的MessageSource
ConfigMessageSource configMessageSource = beanFactory.getBean(configMessageSourceBeanName, ConfigMessageSource.class);
// 如果已经存在MessageSource bean,则将ConfigMessageSource设置为messageSource的parent,将messageSource原来的parent设置为ConfigMessageSource的parent
if (beanFactory.containsLocalBean(messageSourceBeanName)) {
MessageSource messageSource = beanFactory.getBean(messageSourceBeanName, MessageSource.class);
if (messageSource instanceof HierarchicalMessageSource) {
HierarchicalMessageSource hms = (HierarchicalMessageSource) messageSource;
MessageSource pms = hms.getParentMessageSource();
hms.setParentMessageSource(configMessageSource);
configMessageSource.setParentMessageSource(pms);
}
} else {
beanFactory.registerSingleton(messageSourceBeanName, configMessageSource);
}
}
示例3: testAppContextClassHierarchy
import org.springframework.context.support.AbstractApplicationContext; //导入依赖的package包/类
public void testAppContextClassHierarchy() {
Class<?>[] clazz =
ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class, ClassUtils.ClassSet.ALL_CLASSES);
//Closeable.class,
Class<?>[] expected =
new Class<?>[] { OsgiBundleXmlApplicationContext.class,
AbstractDelegatedExecutionApplicationContext.class, AbstractOsgiBundleApplicationContext.class,
AbstractRefreshableApplicationContext.class, AbstractApplicationContext.class,
DefaultResourceLoader.class, ResourceLoader.class,
AutoCloseable.class,
DelegatedExecutionOsgiBundleApplicationContext.class,
ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class,
ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
HierarchicalBeanFactory.class, ApplicationEventPublisher.class, ResourcePatternResolver.class,
MessageSource.class, BeanFactory.class, DisposableBean.class };
assertTrue(compareArrays(expected, clazz));
}
示例4: 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");
}
示例5: 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;
}
示例6: load
import org.springframework.context.support.AbstractApplicationContext; //导入依赖的package包/类
static public AbstractApplicationContext load() {
AbstractApplicationContext context;
try {
context = AnnotationConfigApplicationContext.class.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
AnnotationConfigRegistry registry = (AnnotationConfigRegistry) context;
registry.register(BaseConfiguration.class);
registry.register(GraphQLJavaToolsAutoConfiguration.class);
context.refresh();
return context;
}
示例7: listenersInApplicationContextWithNestedChild
import org.springframework.context.support.AbstractApplicationContext; //导入依赖的package包/类
@Test
public void listenersInApplicationContextWithNestedChild() {
StaticApplicationContext context = new StaticApplicationContext();
RootBeanDefinition nestedChild = new RootBeanDefinition(StaticApplicationContext.class);
nestedChild.getPropertyValues().add("parent", context);
nestedChild.setInitMethodName("refresh");
context.registerBeanDefinition("nestedChild", nestedChild);
RootBeanDefinition listener1Def = new RootBeanDefinition(MyOrderedListener1.class);
listener1Def.setDependsOn("nestedChild");
context.registerBeanDefinition("listener1", listener1Def);
context.refresh();
MyOrderedListener1 listener1 = context.getBean("listener1", MyOrderedListener1.class);
MyEvent event1 = new MyEvent(context);
context.publishEvent(event1);
assertTrue(listener1.seenEvents.contains(event1));
SimpleApplicationEventMulticaster multicaster = context.getBean(
AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME,
SimpleApplicationEventMulticaster.class);
assertFalse(multicaster.getApplicationListeners().isEmpty());
context.close();
assertTrue(multicaster.getApplicationListeners().isEmpty());
}
示例8: 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);
}
示例9: doCreateApplicationContext
import org.springframework.context.support.AbstractApplicationContext; //导入依赖的package包/类
private AbstractApplicationContext doCreateApplicationContext() {
AbstractApplicationContext context = createApplicationContext();
assertNotNull("Should have created a valid Spring application context", context);
String[] profiles = activeProfiles();
if (profiles != null && profiles.length > 0) {
// the context must not be active
if (context.isActive()) {
throw new IllegalStateException("Cannot active profiles: " + Arrays.asList(profiles) + " on active Spring application context: " + context
+ ". The code in your createApplicationContext() method should be adjusted to create the application context with refresh = false as parameter");
}
log.info("Spring activating profiles: {}", Arrays.asList(profiles));
context.getEnvironment().setActiveProfiles(profiles);
}
// ensure the context has been refreshed at least once
if (!context.isActive()) {
context.refresh();
}
return context;
}
示例10: refresh
import org.springframework.context.support.AbstractApplicationContext; //导入依赖的package包/类
/**
* Refreshes the {@link SpringContext}.
*/
public static void refresh()
{
try
{
logger.info("Reloading the App context: " + SpringContext.getConfigFileName());
if (ObjectUtils.isInstanceOf(appContext, AbstractApplicationContext.class))
{
((AbstractApplicationContext) appContext).refresh();
}
logger.info("Successfully Reloaded the App context: " + SpringContext.getConfigFileName());
lastLoaded = System.currentTimeMillis();
}
catch (Exception e)
{
e.printStackTrace(System.err);
logger.error("Context file is not reloaded, got error while reloading the config file.", e);
}
}
示例11: 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);
}
示例12: 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);
}
示例13: main
import org.springframework.context.support.AbstractApplicationContext; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
final String pckName = POIVisualizer.class.getPackage().getName();
try (AbstractApplicationContext ctx = new AnnotationConfigApplicationContext(pckName)) {
POIVisualizer visualizer = ctx.getBean(POIVisualizer.class);
visualizer.start();
}
System.out.println("Exiting");
}
示例14: testCseApplicationListenerThrowException
import org.springframework.context.support.AbstractApplicationContext; //导入依赖的package包/类
@Test
public void testCseApplicationListenerThrowException(@Injectable ContextRefreshedEvent event,
@Injectable AbstractApplicationContext context,
@Injectable BootListener listener,
@Injectable ProducerProviderManager producerProviderManager,
@Mocked RegistryUtils ru) {
Map<String, BootListener> listeners = new HashMap<>();
listeners.put("test", listener);
CseApplicationListener cal = new CseApplicationListener();
cal.setApplicationContext(context);
ReflectUtils.setField(cal, "producerProviderManager", producerProviderManager);
cal.onApplicationEvent(event);
}
示例15: testCseApplicationListenerParentNotnull
import org.springframework.context.support.AbstractApplicationContext; //导入依赖的package包/类
@Test
public void testCseApplicationListenerParentNotnull(@Injectable ContextRefreshedEvent event,
@Injectable AbstractApplicationContext context,
@Injectable AbstractApplicationContext pContext,
@Mocked RegistryUtils ru) {
CseApplicationListener cal = new CseApplicationListener();
cal.setApplicationContext(context);
cal.onApplicationEvent(event);
}