@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(); }
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()); }
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(); } }
@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); }
@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)); }
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(); }
@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(); } }
@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(); } }
@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(); }
@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(); } }
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(); } }
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(); } }
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) { } } } }
@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(); } }
@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("-------"); }
@Test public void Test2(){ ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");//��ʼ������ BuildingLayoutDao buildingLayoutDao = (BuildingLayoutDao) ac.getBean("buildingLayoutDao"); BuildingLayout u = new BuildingLayout(); u.setBuildingId(2); u.setBuildingLayout("һ��һ��"); u.setBuildingLayoutPerPrice(2); u.setBuildingLayoutPicUrl("2112512"); u.setBuildingLayoutReferencePrice(2); u.setBuildingLayoutSoldOut(2); buildingLayoutDao.updateBuildingLayout(u); System.out.println("-------"); }
public static void main(String[] args) { //configuring the application context ApplicationContext ctx=new ClassPathXmlApplicationContext("com/pratik/cfg/config.xml"); //get the bean person p1=(person)ctx.getBean("per"); //get the bean second time person p2=(person)ctx.getBean("per"); System.out.println("\n\t1.Person-->"+p1.hashCode()+"\t1.Employee-->"+p1.getemp().hashCode()); System.out.println("\n\t2.Person-->"+p2.hashCode()+"\t2.Employee-->"+p2.getemp().hashCode()); if(p1.hashCode()==p2.hashCode()) { System.out.println("\t\tPerson is In Singleton"); System.out.println("\t\tEmployee is In Prototype"); }else System.out.println("\t\tExit"); }
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { String config = RedisConsumer.class.getPackage().getName().replace('.', '/') + "/redis-consumer.xml"; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config); context.start(); Map<String, Object> cache = (Map<String, Object>) context.getBean("cache"); cache.remove("hello"); Object value = cache.get("hello"); System.out.println(value); if (value != null) { throw new IllegalStateException(value + " != null"); } cache.put("hello", "world"); value = cache.get("hello"); System.out.println(value); if (! "world".equals(value)) { throw new IllegalStateException(value + " != world"); } }
@Test public void Test4(){ ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");//��ʼ������ BuildingLayoutDao buildingLayoutDao = (BuildingLayoutDao) ac.getBean("buildingLayoutDao"); BuildingLayout u = new BuildingLayout(); u.setBuildingId(2); u.setBuildingLayout("һ��һ��"); u.setBuildingLayoutPerPrice(1); u.setBuildingLayoutPicUrl("2112512"); u.setBuildingLayoutReferencePrice(1); u.setBuildingLayoutSoldOut(1); buildingLayoutDao.deleteBuildingLayout(u); System.out.println(u.getBuildingLayoutPerPrice()); }
@Test public void testDelayOnInitialized() throws Exception { SimpleRegistryService registryService = new SimpleRegistryService(); Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/delay-on-initialized.xml"); //ctx.start(); try { List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService"); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20883/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString()); } finally { ctx.stop(); ctx.close(); exporter.unexport(); } }
static void findTest(){ ApplicationContext atc=new ClassPathXmlApplicationContext("/springContext.xml"); UserService userService1=(UserService)atc.getBean("userService"); atc.getBean(""); PrinterUtils.printILog(userService1); User user =userService1.findUserById("1"); PrinterUtils.printELog(user); }
public static void main(String[] args) { ApplicationContext ctx=new ClassPathXmlApplicationContext("com/pratik/cfg/config.xml"); person p1=(person)ctx.getBean("per"); System.out.println("\n\t1.Person-->"+p1.hashCode()); person p2=(person)ctx.getBean("per"); System.out.println("\n\t1.Person-->"+p2.hashCode()); if(p1.hashCode()==p2.hashCode()) System.out.println("\t\tIn Singleton"); else System.out.println("\t\tIn Prototype"); }
public static ApplicationContext loadSpringApplicationContext(String baseResources) { String applicationContextService = baseResources + "applicationContext-service.xml"; String applicationContextCache = baseResources + "applicationContext-cache.xml"; String[] configLocations = new String[]{ TestCaseUtils.class.getClass().getResource(applicationContextCache).toString(), TestCaseUtils.class.getClass().getResource(applicationContextService).toString() }; return new ClassPathXmlApplicationContext(configLocations); }
public void start() { String configPath = ConfigUtils.getProperty(SPRING_CONFIG); if (configPath == null || configPath.length() == 0) { configPath = DEFAULT_SPRING_CONFIG; } context = new ClassPathXmlApplicationContext(configPath.split("[,\\s]+")); context.start(); }
public static void main( String[] args ) { ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring-configuration.xml"); ReportGenerator generator1 = (ReportGenerator) context.getBean("reportGenerator1"); generator1.format(); ReportGenerator generator2 = (ReportGenerator) context.getBean("reportGenerator2"); generator2.format(); }
public static void main( String[] args ) { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); ProductBoImpl productBo = (ProductBoImpl) context.getBean("productBo"); Product product = productBo.getProductById(3); System.out.println("product name : "+product.getName()); }
public static void main(String[] args) { // TODO Auto-generated method stub ApplicationContext context=new ClassPathXmlApplicationContext("beans_lifecycle.xml"); Demo_DisposableBean obj=(Demo_DisposableBean)context.getBean("obj_Disposable"); System.out.println(obj); ((AbstractApplicationContext)context).registerShutdownHook(); }
public static void main(String[] args) { ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/spring/applicationContext*.xml"); final ContentService contentService = applicationContext.getBean(ContentService.class); Content content = new Content(); content.setContent("哈哈哈"); content.setAddtime(new Date()); content.setUserId(1); content.setLikeNum(0); contentService.add(content); }
@Test public void testMultiProtocol() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol.xml"); ctx.start(); try { DemoService demoService = refer("dubbo://127.0.0.1:20881"); String hello = demoService.sayName("hello"); assertEquals("say:hello", hello); } finally { ctx.stop(); ctx.close(); } }
@SuppressWarnings("resource") @BeforeClass public static void Before(){ ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-context.xml"); userController = applicationContext.getBean(UserController.class); }
@Test public void select() { ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml"); OrderRentHouseDao dao = (OrderRentHouseDao) ac.getBean("orderRentHouseDao"); OrderRentHouse c = new OrderRentHouse(); c.setOrderId(2); System.out.println(dao.selectOrderRentHouse(c).getOrderTime()); }
/** * Tests SQL execution (commit). */ public void testSpringSpringConnectionProvider2() throws Exception { ApplicationContext applicationContext = new ClassPathXmlApplicationContext(APPLICATION_CONTEXT); SpringTestDao springTestDao = (SpringTestDao) applicationContext.getBean("springTestDao"); Book book = new Book(); book.name = "Mirage in Action"; book.author = "Naoki Takezoe"; book.price = 20; springTestDao.insert(book, false); assertEquals(1, springTestDao.getCount()); }
@Before public void setup() { final ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:/jpaSpringContext.xml"); this.factory = ctx.getBean("ticketEntityManagerFactory", EntityManagerFactory.class); this.txManager = ctx.getBean("ticketTransactionManager", PlatformTransactionManager.class); this.dataSource = ctx.getBean("dataSourceTicket", DataSource.class); }
@Test public void ini() throws Exception { ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml"); IniGoodsData i = (IniGoodsData) applicationContext .getBean("iniGoodsData"); i.ini(); }
@Test public void test_noMethodInterface_methodsKeyHasValue() throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-no-methods-interface.xml"); ctx.start(); try { ServiceBean bean = (ServiceBean) ctx.getBean("service"); List<URL> urls = bean.getExportedUrls(); assertEquals(1, urls.size()); URL url = urls.get(0); assertEquals("sayName,getBox", url.getParameter("methods")); } finally { ctx.stop(); ctx.close(); } }
@Before public void setUp() { // Memcached is a required external test fixture. // Abort tests if there is no memcached server available on localhost:11211. final boolean environmentOk = isMemcachedListening(); if (!environmentOk) { logger.warn("Aborting test since no memcached server is available on localhost."); } Assume.assumeTrue(environmentOk); context = new ClassPathXmlApplicationContext("/ticketRegistry-test.xml"); registry = context.getBean(registryBean, MemCacheTicketRegistry.class); }
@Test public void insert() { ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml"); OrderBuildingDao dao = (OrderBuildingDao) ac.getBean("orderBuildingDao"); OrderBuilding c = new OrderBuilding(); c.setAgentId(1); c.setBuildingId(1); c.setOrderStatus("���"); c.setOrderTime(new Date()); c.setUserId(1); c.setUserPhoneNumber("18059xxxxxx"); dao.insertOrderBuilding(c); }
@Test public void testMultiProtocolDefault() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-default.xml"); ctx.start(); try { DemoService demoService = refer("rmi://127.0.0.1:10991"); String hello = demoService.sayName("hello"); assertEquals("say:hello", hello); } finally { ctx.stop(); ctx.close(); } }
@SuppressWarnings("resource") public BookService() { // 容器 ApplicationContext ctx = new ClassPathXmlApplicationContext("/com/demo/ioca/IOCBeans.xml"); // 从容器中获得id为bookdao的bean bookDAO = (IBookDAO) ctx.getBean("bookdao"); }