本文整理匯總了Java中org.springframework.context.support.GenericXmlApplicationContext.getBean方法的典型用法代碼示例。如果您正苦於以下問題:Java GenericXmlApplicationContext.getBean方法的具體用法?Java GenericXmlApplicationContext.getBean怎麽用?Java GenericXmlApplicationContext.getBean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.context.support.GenericXmlApplicationContext
的用法示例。
在下文中一共展示了GenericXmlApplicationContext.getBean方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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());
}
示例3: 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());
}
示例4: 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());
}
示例5: 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());
}
示例6: 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);
}
示例7: 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);
}
示例8: createNetworkDiscoverer
import org.springframework.context.support.GenericXmlApplicationContext; //導入方法依賴的package包/類
private NetworkDiscoverer createNetworkDiscoverer(String projectPath, String version, int initialNumberOfThreads, int maxNumberOfThreads) {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.load("classpath:netDiscoverer/netDiscoverer.xml");
ctx.load("classpath:csvConnectionDetails/csvConnectionDetailsFactory.xml");
AbstractBeanDefinition projectPathBeanDefinition = BeanDefinitionBuilder.rootBeanDefinition(String.class)
.addConstructorArgValue(projectPath).getBeanDefinition();
BeanDefinition labelDirNameBeanDefinition = BeanDefinitionBuilder.
rootBeanDefinition(String.class)
.addConstructorArgValue(version).getBeanDefinition();
BeanDefinition versionBeanDefinition = BeanDefinitionBuilder.
rootBeanDefinition(String.class)
.addConstructorArgValue(version).getBeanDefinition();
ctx.registerBeanDefinition("projectPath", projectPathBeanDefinition);
ctx.registerBeanDefinition("labelDirName", labelDirNameBeanDefinition);
ctx.registerBeanDefinition("version", versionBeanDefinition);
ctx.refresh();
NetworkDiscoverer discoverer = ctx.getBean("parallelSnmpDiscovery", NetworkDiscoverer.class);
return discoverer;
}
示例9: setup
import org.springframework.context.support.GenericXmlApplicationContext; //導入方法依賴的package包/類
@Before
public void setup() {
String baseDir = System.getProperty("base.dir");
if (baseDir==null){
baseDir=".";
}
System.out.println("BaseDir:"+new File(baseDir).getAbsolutePath());
Map<String,String> properties = new HashMap<>();
String projectDir = new File(baseDir,"projectManager/fileBasedProjectManager/src/test/resources").getAbsolutePath();
properties.put("baseDir", baseDir);
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.refresh();
ctx.load("classpath:fileBasedProjectManager/fileBasedProjectManager.xml");
FileBasedProjectManagerFactory fileBasedProjectManagerFactory = ctx.getBean("projectManagerFactory", FileBasedProjectManagerFactory.class);
fileBasedProjectManager = fileBasedProjectManagerFactory.createProjectManager(properties);
projectName = fileBasedProjectManager.randomProjectNameGenerator(projectDir);
}
示例10: createTopologyViewer
import org.springframework.context.support.GenericXmlApplicationContext; //導入方法依賴的package包/類
private TopologyViewer createTopologyViewer(String projectPath, String projectType) {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.load("classpath:discoveryResultTopologyViewer/discoveryResultTopologyViewer.xml");
ctx.load("classpath:xmlTopologyViewerConfig/xmlTopologyViewerConfig.xml");
ctx.load("classpath:xmlNodeDataProvider/xmlNodeDataProvider.xml");
AbstractBeanDefinition projectPathBeanDefinition = BeanDefinitionBuilder.rootBeanDefinition(String.class)
.addConstructorArgValue(projectPath).getBeanDefinition();
AbstractBeanDefinition projectTypeBeanDefinition = BeanDefinitionBuilder.rootBeanDefinition(String.class)
.addConstructorArgValue(projectType).getBeanDefinition();
ctx.registerBeanDefinition("projectPath", projectPathBeanDefinition);
ctx.registerBeanDefinition("projectType", projectTypeBeanDefinition);
ctx.refresh();
TopologyViewer topologyViewer = ctx.getBean("discoveryResultTopologyViewer", TopologyViewer.class);
return topologyViewer;
}
示例11: resourceIdResolver_stackConfiguration_resourceIdResolverBeanExposed
import org.springframework.context.support.GenericXmlApplicationContext; //導入方法依賴的package包/類
@Test
public void resourceIdResolver_stackConfiguration_resourceIdResolverBeanExposed() {
// Arrange
GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
AmazonCloudFormation amazonCloudFormation = Mockito.mock(AmazonCloudFormation.class);
when(amazonCloudFormation.listStackResources(new ListStackResourcesRequest().withStackName("IntegrationTestStack"))).
thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary()));
applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-staticStackName.xml", getClass()));
applicationContext.getBeanFactory().registerSingleton(getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation);
applicationContext.refresh();
// Act
ResourceIdResolver resourceIdResolver = applicationContext.getBean(ResourceIdResolver.class);
// Assert
assertThat(resourceIdResolver, is(not(nullValue())));
}
開發者ID:spring-cloud,項目名稱:spring-cloud-aws,代碼行數:21,代碼來源:StackConfigurationBeanDefinitionParserTest.java
示例12: GenericXmlApplicationContext
import org.springframework.context.support.GenericXmlApplicationContext; //導入方法依賴的package包/類
@Test
public void stackResourceRegistry_stackConfigurationWithStaticName_stackResourceRegistryBeanExposedUnderStaticStackName() throws Exception {
// Arrange
GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
AmazonCloudFormation amazonCloudFormation = Mockito.mock(AmazonCloudFormation.class);
when(amazonCloudFormation.listStackResources(new ListStackResourcesRequest().withStackName("IntegrationTestStack"))).
thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary()));
applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-staticStackName.xml", getClass()));
applicationContext.getBeanFactory().registerSingleton(getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation);
applicationContext.refresh();
// Act
StackResourceRegistry staticStackNameProviderBasedStackResourceRegistry = applicationContext.getBean("IntegrationTestStack", StackResourceRegistry.class);
// Assert
assertThat(staticStackNameProviderBasedStackResourceRegistry, is(not(nullValue())));
}
開發者ID:spring-cloud,項目名稱:spring-cloud-aws,代碼行數:21,代碼來源:StackConfigurationBeanDefinitionParserTest.java
示例13: setUp
import org.springframework.context.support.GenericXmlApplicationContext; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception
{
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.setValidating(false);
context.load("classpath:spring/applicationContext*.xml");
context.refresh();
edi = context.getBean(ItemService.class);
}
示例14: setUp
import org.springframework.context.support.GenericXmlApplicationContext; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception
{
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.setValidating(false);
context.load("classpath:spring/applicationContext*.xml");
context.refresh();
edi = context.getBean(EdiUserService.class);
}
示例15: 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 = (ITestBean) context.getBean("target");
testBean.test();
testBean.await(3000);
Thread asyncThread = testBean.getThread();
assertTrue(asyncThread.getName().startsWith("testExecutor"));
context.close();
}