本文整理匯總了Java中org.springframework.context.support.ClassPathXmlApplicationContext.getBean方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassPathXmlApplicationContext.getBean方法的具體用法?Java ClassPathXmlApplicationContext.getBean怎麽用?Java ClassPathXmlApplicationContext.getBean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.context.support.ClassPathXmlApplicationContext
的用法示例。
在下文中一共展示了ClassPathXmlApplicationContext.getBean方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testInitReference
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
@Test
public void testInitReference() throws Exception {
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider.xml");
providerContext.start();
try {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference.xml");
ctx.start();
try {
DemoService demoService = (DemoService)ctx.getBean("demoService");
assertEquals("say:world", demoService.sayName("world"));
} finally {
ctx.stop();
ctx.close();
}
} finally {
providerContext.stop();
providerContext.close();
}
}
示例2: testAnnotation
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
@Test
public void testAnnotation() {
SimpleRegistryService registryService = new SimpleRegistryService();
Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
try {
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml");
providerContext.start();
try {
ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-consumer.xml");
consumerContext.start();
try {
AnnotationAction annotationAction = (AnnotationAction) consumerContext.getBean("annotationAction");
String hello = annotationAction.doSayName("hello");
assertEquals("annotation:hello", hello);
} finally {
consumerContext.stop();
consumerContext.close();
}
} finally {
providerContext.stop();
providerContext.close();
}
} finally {
exporter.unexport();
}
}
示例3: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String config = AsyncConsumer.class.getPackage().getName().replace('.', '/') + "/async-consumer.xml";
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
context.start();
final AsyncService asyncService = (AsyncService)context.getBean("asyncService");
Future<String> f = RpcContext.getContext().asyncCall(new Callable<String>() {
public String call() throws Exception {
return asyncService.sayHello("async call request");
}
});
System.out.println("async call ret :" + f.get());
RpcContext.getContext().asyncCall(new Runnable() {
public void run() {
asyncService.sayHello("oneway call request1");
asyncService.sayHello("oneway call request2");
}
});
System.in.read();
}
示例4: contextInitialized
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
@Override
public void contextInitialized(ServletContextEvent evt)
{
log.debug("Load data");
ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
InitServiceI initService = (InitServiceI) ctx
.getBean("demoInitService");
try
{
initService.init();
// File file = new File(this.getClass().getClassLoader()
// .getResource(("applicationContext.xml")).getFile());
// SysConfig.Catalog_Project = file.getAbsolutePath().replace(
// "applicationContext.xml", "");
} catch (IOException e)
{
e.printStackTrace();
}
}
示例5: setup
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
@Before
public void setup() throws Exception {
final ClassPathXmlApplicationContext ctx = new
ClassPathXmlApplicationContext("classpath:/jpaTestApplicationContext.xml");
this.dataSource = ctx.getBean("dataSource", DataSource.class);
final Connection c = this.dataSource.getConnection();
final Statement s = c.createStatement();
c.setAutoCommit(true);
s.execute(getSqlInsertStatementToCreateUserAccount(0));
for (int i = 0; i < 10; i++) {
s.execute(getSqlInsertStatementToCreateUserAccount(i));
}
c.close();
}
開發者ID:yuweijun,項目名稱:cas-server-4.2.1,代碼行數:18,代碼來源:QueryAndEncodeDatabaseAuthenticationHandlerTests.java
示例6: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[]{"dubbo-comsumer.xml"});
context.start();
// obtain proxy object for remote invocation
DemoService demoService = (DemoService) context.getBean("demoService");
// execute remote invocation
String hello = demoService.sayHello("world");
// show the result
System.out.println(hello);
}
示例7: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String config = GenericConsumer.class.getPackage().getName().replace('.', '/') + "/generic-consumer.xml";
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
context.start();
IUserService userservice = (IUserService) context.getBean("userservice");
User user = userservice.get(new Params("a=b"));
System.out.println(user);
System.in.read();
}
示例8: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("dubbo-demo-consumer.xml");
context.start();
Demo.Iface demo = (Demo.Iface) context.getBean("demoService");
System.out.println(demo.echoI32(32));
for (int i = 0; i < 10; i++) {
System.out.println(demo.echoI32(i + 1));
}
context.close();
}
示例9: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String config = CallbackConsumer.class.getPackage().getName().replace('.', '/') + "/callback-consumer.xml";
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
context.start();
CallbackService callbackService = (CallbackService) context.getBean("callbackService");
callbackService.addListener("foo.bar", new CallbackListener() {
public void changed(String msg) {
System.out.println("callback1:" + msg);
}
});
System.in.read();
}
示例10: testGenericServiceConfigThroughSpring
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
@Test
public void testGenericServiceConfigThroughSpring() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/generic-export.xml");
try {
ctx.start();
ServiceConfig serviceConfig = (ServiceConfig) ctx.getBean("dubboDemoService");
URL url = (URL)serviceConfig.getExportedUrls().get(0);
Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
} finally {
ctx.destroy();
}
}
示例11: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String config = VersionConsumer.class.getPackage().getName().replace('.', '/') + "/version-consumer.xml";
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
context.start();
VersionService versionService = (VersionService) context.getBean("versionService");
for (int i = 0; i < 10000; i ++) {
String hello = versionService.sayHello("world");
System.out.println(hello);
Thread.sleep(2000);
}
System.in.read();
}
示例12: test_RpcContext_getUrls
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
@Test
public void test_RpcContext_getUrls() throws Exception {
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(
ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-long-waiting.xml");
providerContext.start();
try {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
ConfigTest.class.getPackage().getName().replace('.', '/')
+ "/init-reference-getUrls.xml");
ctx.start();
try {
DemoService demoService = (DemoService) ctx.getBean("demoService");
try {
demoService.sayName("Haha");
fail();
} catch (RpcException expected) {
assertThat(expected.getMessage(), containsString("Tried 3 times"));
}
assertEquals(3, RpcContext.getContext().getUrls().size());
} finally {
ctx.stop();
ctx.close();
}
} finally {
providerContext.stop();
providerContext.close();
}
}
示例13: initContext
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
@BeforeTest
public void initContext() {
context = new ClassPathXmlApplicationContext("classpath:test-commons-context.xml");
consumer = context.getBean(JMSConsumer.class);
searchPublisher = context.getBean(SearchPublisher.class);
retryDir = context.getBean("retryDir", String.class);
while (!consumer.isStarted()) {
//wait until the consumers are started
}
}
示例14: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String config = JacksonConsumer.class.getPackage().getName().replace('.', '/') + "/jackson-consumer.xml";
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
context.start();
JacksonService jacksonService = (JacksonService) context.getBean("jacksonService");
System.out.println("TEST: sayHello");
String hello = jacksonService.sayHello("world");
System.out.println(hello);
System.out.println("TEST: testJacksonBean");
JacksonBean jacksonBean = jacksonService.testJacksonBean(new JacksonBean(), new JacksonInnerBean());
System.out.println(jacksonBean);
System.out.println("TEST: testInheritBean");
Inherit inherit = jacksonService.testInheritBean(new InheritBean(), new JacksonBean());
System.out.println(inherit);
System.out.println("TEST: testArray");
int[] intArray = jacksonService.testArray(new int[]{1,2});
System.out.println(Arrays.toString(intArray));
System.out.println("TEST: testBeanArray");
JacksonBean[] beanArray = jacksonService.testBeanArray(new JacksonBean[]{new JacksonBean(), new JacksonBean()});
System.out.println(Arrays.toString(beanArray));
System.out.println("TEST: testException");
try {
jacksonService.testException();
} catch(Exception e){
System.out.println("exception : " + e.getClass() + " : " + e.getMessage());
}
System.in.read();
}
示例15: init
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
@Before
public void init() {
context = new ClassPathXmlApplicationContext("applicationContext.xml");
service = context.getBean(NCacheService.class);
}