本文整理匯總了Java中org.springframework.context.support.GenericXmlApplicationContext類的典型用法代碼示例。如果您正苦於以下問題:Java GenericXmlApplicationContext類的具體用法?Java GenericXmlApplicationContext怎麽用?Java GenericXmlApplicationContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GenericXmlApplicationContext類屬於org.springframework.context.support包,在下文中一共展示了GenericXmlApplicationContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
// Create test context
try (final GenericXmlApplicationContext generateContext = new GenericXmlApplicationContext()) {
generateContext.load("classpath:generate-context.xml");
generateContext.refresh();
final DataSource dataSource = generateContext.getBean(DataSource.class);
final Generator generator = new Generator(getLog(), this::processRecord);
getLog().info("Loading templates from: " + source.getAbsolutePath());
getLog().info("Package: " + packageName);
for (final File file : source.listFiles(this::acceptAllFiles)) {
generator.generate(dataSource, file, destination, packageName);
}
}
}
示例2: configuredThroughNamespace
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
@Test
public void configuredThroughNamespace() {
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.load(new ClassPathResource("taskNamespaceTests.xml", getClass()));
context.refresh();
ITestBean testBean = context.getBean("target", ITestBean.class);
testBean.test();
testBean.await(3000);
Thread asyncThread = testBean.getThread();
assertTrue(asyncThread.getName().startsWith("testExecutor"));
TestableAsyncUncaughtExceptionHandler exceptionHandler =
context.getBean("exceptionHandler", TestableAsyncUncaughtExceptionHandler.class);
assertFalse("handler should not have been called yet", exceptionHandler.isCalled());
testBean.failWithVoid();
exceptionHandler.await(3000);
Method m = ReflectionUtils.findMethod(TestBean.class, "failWithVoid");
exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class);
context.close();
}
示例3: testJavaBean
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
@Test
public void testJavaBean() {
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-java-context.xml");
TestService bean = context.getBean("javaBean", TestService.class);
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class);
assertEquals(0, logAdvice.getCountThrows());
try {
bean.sayHello();
fail("Expected exception");
}
catch (RuntimeException ex) {
assertEquals("TestServiceImpl", ex.getMessage());
}
assertEquals(1, logAdvice.getCountThrows());
}
示例4: testGroovyBeanInterface
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
@Test
public void testGroovyBeanInterface() {
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-interface-context.xml");
TestService bean = context.getBean("groovyBean", TestService.class);
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class);
assertEquals(0, logAdvice.getCountThrows());
try {
bean.sayHello();
fail("Expected exception");
}
catch (RuntimeException ex) {
assertEquals("GroovyServiceImpl", ex.getMessage());
}
assertEquals(1, logAdvice.getCountThrows());
}
示例5: testGroovyBeanDynamic
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
@Test
public void testGroovyBeanDynamic() {
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-dynamic-context.xml");
TestService bean = context.getBean("groovyBean", TestService.class);
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class);
assertEquals(0, logAdvice.getCountThrows());
try {
bean.sayHello();
fail("Expected exception");
}
catch (RuntimeException ex) {
assertEquals("GroovyServiceImpl", ex.getMessage());
}
// No proxy here because the pointcut only applies to the concrete class, not the interface
assertEquals(0, logAdvice.getCountThrows());
assertEquals(0, logAdvice.getCountBefore());
}
示例6: testGroovyBeanProxyTargetClass
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
@Test
public void testGroovyBeanProxyTargetClass() {
context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-proxy-target-class-context.xml");
TestService bean = context.getBean("groovyBean", TestService.class);
LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class);
assertEquals(0, logAdvice.getCountThrows());
try {
bean.sayHello();
fail("Expected exception");
}
catch (TestException ex) {
assertEquals("GroovyServiceImpl", ex.getMessage());
}
assertEquals(1, logAdvice.getCountBefore());
assertEquals(1, logAdvice.getCountThrows());
}
示例7: xml
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
@Test
public void xml() {
ConfigurableApplicationContext ctx = new GenericXmlApplicationContext(
getClass(), "DestroyMethodInferenceTests-context.xml");
WithLocalCloseMethod x1 = ctx.getBean("x1", WithLocalCloseMethod.class);
WithLocalCloseMethod x2 = ctx.getBean("x2", WithLocalCloseMethod.class);
WithLocalCloseMethod x3 = ctx.getBean("x3", WithLocalCloseMethod.class);
WithNoCloseMethod x4 = ctx.getBean("x4", WithNoCloseMethod.class);
WithInheritedCloseMethod x8 = ctx.getBean("x8", WithInheritedCloseMethod.class);
assertThat(x1.closed, is(false));
assertThat(x2.closed, is(false));
assertThat(x3.closed, is(false));
assertThat(x4.closed, is(false));
ctx.close();
assertThat(x1.closed, is(false));
assertThat(x2.closed, is(true));
assertThat(x3.closed, is(true));
assertThat(x4.closed, is(false));
assertThat(x8.closed, is(false));
}
示例8: testContextConfiguration
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
private void testContextConfiguration(String profile, String springProfile) {
GenericXmlApplicationContext context = createContext(profile, springProfile);
AutowireCapableBeanFactory factory = context.getAutowireCapableBeanFactory();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
ResourceLoader resourceLoader = new MultiLoader(classLoader);
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
Collection<Class<?>> descendants = classFinder.getDescendants(Object.class, "com.hotwire.test.steps");
List<Throwable> throwables = new ArrayList<>();
for (Class<?> clazz : descendants) {
if (Utils.isInstantiable(clazz) & !clazz.isEnum()) {
context.registerBeanDefinition(clazz.getName(),
BeanDefinitionBuilder.genericBeanDefinition(clazz).getBeanDefinition());
try {
factory.getBean(clazz.getName());
}
catch (Throwable t) {
while (t.getCause() != null) {
t = t.getCause();
}
System.err.println(t.getMessage());
throwables.add(t);
}
}
}
assertThat(throwables)
.as("List of throwables should be empty!")
.isEmpty();
}
示例9: configureMergedItems
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
@PostConstruct
public void configureMergedItems() {
Set<Resource> temp = new LinkedHashSet<Resource>();
if (mergedEntityContexts != null && !mergedEntityContexts.isEmpty()) {
for (String location : mergedEntityContexts) {
temp.add(webApplicationContext.getResource(location));
}
}
if (entityContexts != null) {
for (Resource resource : entityContexts) {
temp.add(resource);
}
}
entityContexts = temp.toArray(new Resource[temp.size()]);
applicationcontext = new GenericXmlApplicationContext(entityContexts);
}
示例10: buildProcessEngine
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
public static ProcessEngine buildProcessEngine(URL resource) {
log.fine("==== BUILDING SPRING APPLICATION CONTEXT AND PROCESS ENGINE =========================================");
ApplicationContext applicationContext = new GenericXmlApplicationContext(new UrlResource(resource));
Map<String, ProcessEngine> beansOfType = applicationContext.getBeansOfType(ProcessEngine.class);
if ( (beansOfType==null)
|| (beansOfType.isEmpty())
) {
throw new ActivitiException("no "+ProcessEngine.class.getName()+" defined in the application context "+resource.toString());
}
ProcessEngine processEngine = beansOfType.values().iterator().next();
log.fine("==== SPRING PROCESS ENGINE CREATED ==================================================================");
return processEngine;
}
示例11: renewTestData
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
private static void renewTestData() {
ctx = new GenericXmlApplicationContext();
ctx.load("classpath:datasource-context-h2-embedded.xml");
ctx.refresh();
fileEntityDao = ctx.getBean("fileEntityDao", FileEntityDao.class);
assertNotNull(fileEntityDao);
try {
FileUtils.deleteDirectory(new File(filesHomePath));
} catch (IOException e) {
e.printStackTrace();
}
TestUtil.touchTestFilesForFileBox(fileEntityDao);
}
示例12: enhanceExistingSpringWebApplicationContext
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
private void enhanceExistingSpringWebApplicationContext(ServletContextEvent sce, WebApplicationContext wac) {
LOGGER.info("Enhancing existing Spring application context...");
String cosmoContextLocation = sce.getServletContext().getInitParameter(CONTEXT_PARAM_NAME);
@SuppressWarnings("resource")
GenericXmlApplicationContext cosmoAppCtxt = new GenericXmlApplicationContext();
cosmoAppCtxt.setEnvironment((ConfigurableEnvironment) wac.getEnvironment());
cosmoAppCtxt.load(cosmoContextLocation);
cosmoAppCtxt.refresh();
cosmoAppCtxt.start();
//make beans that are required from web components (as delegating filter proxy) accesible
((AbstractRefreshableWebApplicationContext)wac).getBeanFactory().setParentBeanFactory(cosmoAppCtxt.getBeanFactory());
LOGGER.info("Enhanced existing Spring application context started");
}
示例13: main
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
/**
* The main method.
*
* @param args
* the arguments
* @throws Exception
* the exception
*/
public static void main(String[] args) throws Exception {
logger.info("Starting at {}...", new Date().toString());
try {
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.load("classpath:/META-INF/spring/applicationContext*.xml");
context.refresh();
} catch (Exception e) {
logger.error("Error occurred:", e);
throw e;
}
while (true) {
}
}
示例14: bootstrapAppFromXml
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
@Test
public void bootstrapAppFromXml() {
// Here cannot use WEB-INF/spring/root-context.xml
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.load("classpath:META-INF/spring/applicationContext*.xml");
context.refresh();
assertThat(context, is(notNullValue()));
// EchoSignPollingService
EsignaturePollingService esignaturePollingService = (EsignaturePollingService)(context.getBean("esignaturePollingService"));
assertNotNull(esignaturePollingService);
// EchoSignPollingService
//EchoSignPollingService echoSignPollingService = (EchoSignPollingService)(context.getBean("esignaturePollingService"));
//assertNotNull(echoSignPollingService);
}
示例15: unsubscribe
import org.springframework.context.support.GenericXmlApplicationContext; //導入依賴的package包/類
public void unsubscribe(String subscriptionID) {
ApplicationContext ctx = new GenericXmlApplicationContext(
"classpath:MongoConfig.xml");
MongoOperations mongoOperation = (MongoOperations) ctx
.getBean("mongoTemplate");
// Its size should be 0 or 1
List<SubscriptionType> subscriptions = mongoOperation.find(new Query(
Criteria.where("subscriptionID").is(subscriptionID)),
SubscriptionType.class);
for (int i = 0; i < subscriptions.size(); i++) {
SubscriptionType subscription = subscriptions.get(i);
// Remove from current Quartz
removeScheduleFromQuartz(subscription);
// Remove from DB list
removeScheduleFromDB(mongoOperation, subscription);
}
((AbstractApplicationContext) ctx).close();
}