本文整理匯總了Java中org.springframework.context.support.ClassPathXmlApplicationContext類的典型用法代碼示例。如果您正苦於以下問題:Java ClassPathXmlApplicationContext類的具體用法?Java ClassPathXmlApplicationContext怎麽用?Java ClassPathXmlApplicationContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ClassPathXmlApplicationContext類屬於org.springframework.context.support包,在下文中一共展示了ClassPathXmlApplicationContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public static void main (String[] args){
ConfigurableApplicationContext ac =
new ClassPathXmlApplicationContext("/context.xml");
PollableChannel feedChannel = ac.getBean("feedChannel", PollableChannel.class);
for (int i = 0; i < 10; i++) {
Message<SyndEntry> message = (Message<SyndEntry>) feedChannel.receive(1000);
if (message != null){
System.out.println("==========="+i+"===========");
SyndEntry entry = message.getPayload();
System.out.println(entry.getAuthor());
System.out.println(entry.getPublishedDate());
System.out.println(entry.getTitle());
System.out.println(entry.getUri());
System.out.println(entry.getLink());
System.out.println("======================");
}
}
ac.close();
}
示例2: testBootstrapAndShutdown
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入依賴的package包/類
public void testBootstrapAndShutdown() throws Exception
{
// now bring up the bootstrap
ApplicationContext ctx = new ClassPathXmlApplicationContext(APP_CONTEXT_XML);
// the folder should be gone
assertFalse("Folder was not deleted by bootstrap", dir.exists());
// now create the folder again
dir.mkdir();
assertTrue("Directory not created", dir.exists());
// announce that the context is closing
ctx.publishEvent(new ContextClosedEvent(ctx));
// the folder should be gone
assertFalse("Folder was not deleted by shutdown", dir.exists());
}
示例3: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入依賴的package包/類
public static void main(String args[]){
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:applicationContext-service.xml"});
HBaseService hbaseService = (HBaseService) ctx.getBean("HBaseService");
GroupDataDao groupDatadao = (GroupDataDao) ctx.getBean("groupDataDao");
GroupData groupData = new GroupData();
try{
groupData.setTime_id("test");
groupData.setRecord_time("test");
groupData.setAddr("test");
groupData.setDataList("test");
groupData.setProbe_id("test");
groupData.setLat("test");
groupData.setLon("test");
groupData.setMmac("test");
groupData.setWmac("test");
groupData.setWssid("test");
groupData.setRate("test");
groupDatadao.save(groupData);
System.out.println("Finish");
}catch (Exception e){
e.printStackTrace();
}
}
示例4: testPageHelper
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入依賴的package包/類
@Test
public void testPageHelper() {
//創建一個spring容器
ApplicationContext applicationContext =
new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");
//送spring容器中獲得mapper代理對象
TbItemMapper itemMapper = applicationContext.getBean(TbItemMapper.class);
//執行查詢並分頁
TbItemExample tbItemExample = new TbItemExample();
//分頁處理
PageHelper.startPage(1, 10);
List<TbItem> list = itemMapper.selectByExample(tbItemExample);
//獲取商品列表
for (TbItem tbItem : list) {
System.out.println(tbItem.getTitle());
}
//取分頁信息
PageInfo<TbItem> pageInfo = new PageInfo<>(list);
long total = pageInfo.getTotal();
System.out.println("共有商品:" + total);
}
示例5: delete
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入依賴的package包/類
@Test
public void delete() {
ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
OrderRentHouseDao dao = (OrderRentHouseDao) ac.getBean("orderRentHouseDao");
OrderRentHouse c = new OrderRentHouse();
c.setOrderId(1);
System.out.println(dao.deleteOrderRentHouse(c));
}
示例6: 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();
}
示例7: 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();
}
}
示例8: testSystemPropertyOverrideMultiProtocol
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入依賴的package包/類
@Test
public void testSystemPropertyOverrideMultiProtocol() throws Exception {
System.setProperty("dubbo.protocol.dubbo.port", "20814");
System.setProperty("dubbo.protocol.rmi.port", "10914");
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/override-multi-protocol.xml");
providerContext.start();
try {
ProtocolConfig dubbo = (ProtocolConfig) providerContext.getBean("dubbo");
assertEquals(20814, dubbo.getPort().intValue());
ProtocolConfig rmi = (ProtocolConfig) providerContext.getBean("rmi");
assertEquals(10914, rmi.getPort().intValue());
} finally {
System.setProperty("dubbo.protocol.dubbo.port", "");
System.setProperty("dubbo.protocol.rmi.port", "");
providerContext.stop();
providerContext.close();
}
}
示例9: 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);
this.handler = new SearchModeSearchDatabaseAuthenticationHandler();
handler.setDataSource(this.dataSource);
handler.setTableUsers("cassearchusers");
handler.setFieldUser("username");
handler.setFieldPassword("password");
handler.afterPropertiesSet();
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,代碼行數:27,代碼來源:SearchModeSearchDatabaseAuthenticationHandlerTests.java
示例10: testXmlOverrideProperties
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入依賴的package包/類
@Test
public void testXmlOverrideProperties() throws Exception {
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/xml-override-properties.xml");
providerContext.start();
try {
ApplicationConfig application = (ApplicationConfig) providerContext.getBean("application");
assertEquals("demo-provider", application.getName());
assertEquals("world", application.getOwner());
RegistryConfig registry = (RegistryConfig) providerContext.getBean("registry");
assertEquals("N/A", registry.getAddress());
ProtocolConfig dubbo = (ProtocolConfig) providerContext.getBean("dubbo");
assertEquals(20813, dubbo.getPort().intValue());
} finally {
providerContext.stop();
providerContext.close();
}
}
示例11: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入依賴的package包/類
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
// case1:
ApplicationContext context = new ClassPathXmlApplicationContext(
"beans_classpath.xml");
// case2
ApplicationContext context1 = new ClassPathXmlApplicationContext(
new String[] { "beans_classpath.xml","beans_classpath1.xml" });
System.out.println("container created successfully");
} catch (BeansException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例12: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入依賴的package包/類
public static void main(String[] args) throws InterruptedException {
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"test-schduler.xml");
InstanceFactory.setInstanceProvider(new SpringInstanceProvider(context));
logger.info("TASK started....");
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
logger.info("TASK Stoped....");
context.close();
}
}));
Scanner scan = new Scanner(System.in);
String cmd = scan.next();
if ("q".equals(cmd)) {
scan.close();
context.close();
}
}
示例13: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入依賴的package包/類
public static void main(String[] args){
ClassPathXmlApplicationContext cac = new ClassPathXmlApplicationContext("classpath*:worker2.xml","classpath*:spring/spring-worker-db.xml");
cac.start();
/*GenericApplicationContext gac = new GenericApplicationContext();
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(gac);
xmlReader.loadBeanDefinitions(new ClassPathResource("worker2.xml"));
xmlReader.loadBeanDefinitions(new ClassPathResource("spring/spring-worker-db.xml"));
// PropertiesBeanDefinitionReader propReader = new PropertiesBeanDefinitionReader(gac);
// propReader.loadBeanDefinitions(new ClassPathResource("db.properties"));
gac.refresh();*/
logger.info("Worker Server服務啟動完成");
// 啟動本地服務,然後hold住本地服務
synchronized (StartWorkerServer.class) {
while (true) {
try {
StartWorkerServer.class.wait();
} catch (InterruptedException e) {
}
}
}
}
示例14: testRedisClient
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入依賴的package包/類
@Test
public void testRedisClient() throws Exception {
RedisRunner.RedisProcess run = new RedisRunner()
.requirepass("do_not_use_if_it_is_not_set")
.nosave()
.randomDir()
.run();
try {
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext("classpath:org/redisson/spring/support/namespace_wiki_redis_client.xml");
RedisClient redisClient = context.getBean(RedisClient.class);
RedisConnection connection = redisClient.connect();
Map<String, String> info = connection.sync(RedisCommands.INFO_ALL);
assertThat(info, notNullValue());
assertThat(info, not(info.isEmpty()));
((ConfigurableApplicationContext) context).close();
} finally {
run.stop();
}
}
示例15: Test2
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入依賴的package包/類
@Test
public void Test2(){
ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");//��ʼ������
BuildingDealDao buildingDealDao = (BuildingDealDao) ac.getBean("buildingDealDao");
BuildingDeal u = new BuildingDeal();
u.setAgentId(2);
u.setBuildingDealPerPrice(100);
u.setBuildingDealTime(new Date());
u.setBuildingDealTotalPrice(100);
u.setBuildingId(1);
u.setBuildingLayout("����һ��");
u.setUserId(1);
u.setBuildingDealId(1);
buildingDealDao.updateBuildingDeal(u);
System.out.println("-------");
}