Example usage for org.springframework.context.support FileSystemXmlApplicationContext getBean

List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.context.support FileSystemXmlApplicationContext getBean.

Prototype

@Override
    public Object getBean(String name) throws BeansException 

Source Link

Usage

From source file:com.browseengine.bobo.api.BoboIndexReader.java

private static Collection<FacetHandler<?>> loadFromIndex(File file, WorkArea workArea) throws IOException {
    // File springFile = new File(file, SPRING_CONFIG);
    // FileSystemXmlApplicationContext appCtx =
    //   new FileSystemXmlApplicationContext("file:" + springFile.getAbsolutePath());
    //return (Collection<FacetHandler<?>>) appCtx.getBean("handlers");

    Set<Entry<Class<?>, Object>> entries = workArea.map.entrySet();
    FileSystemXmlApplicationContext appCtx = new FileSystemXmlApplicationContext();
    for (Entry<Class<?>, Object> entry : entries) {
        Object obj = entry.getValue();
        if (obj instanceof ClassLoader) {
            appCtx.setClassLoader((ClassLoader) obj);
            break;
        }//from   w  w  w .  ja va 2s.  co  m
    }

    String absolutePath = file.getAbsolutePath();
    String partOne = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator));
    String partTwo = URLEncoder.encode(absolutePath.substring(absolutePath.lastIndexOf(File.separator) + 1),
            "UTF-8");
    absolutePath = partOne + File.separator + partTwo;

    File springFile = new File(new File(absolutePath), SPRING_CONFIG);
    appCtx.setConfigLocation("file:" + springFile.getAbsolutePath());
    appCtx.refresh();

    return (Collection<FacetHandler<?>>) appCtx.getBean("handlers");

}

From source file:com.yuwang.pinju.core.shop.ao.TestShopOpenAO.java

License:asdf

/**
 * ??/*from   w  w  w  .j  ava  2s. c o m*/
 * @throws DaoException
 */
@Test
public void testSaveShopInfo() throws DaoException {
    FileSystemXmlApplicationContext factory = new FileSystemXmlApplicationContext(
            "/src/test/resources/applicationContext.xml");
    ShopShowInfoManager shopShowInfoManager = (ShopShowInfoManager) factory.getBean("shopShowInfoManager");
    List<Long> userIdList = new ArrayList<Long>();
    userIdList.add(100000055000000l);
    List reultList;
    try {
        reultList = shopShowInfoManager.queryShopInfoByUserIdList(userIdList);
        log.info(reultList);
        log.info(reultList.size());
        //         log.info(((ShopInfoAllDO)reultList.get(0)).getName());

    } catch (ManagerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    //      FileSystemXmlApplicationContext factory = new FileSystemXmlApplicationContext("/src/test/resources/applicationContext.xml");
    //      ShopOpenAO shopOpenAO = (ShopOpenAO)factory.getBean("shopOpenAO");
    //   
    //      /**
    //       * ?C?
    //       */
    //      ShopCustomerInfoDO shopCustomerInfoDO = new ShopCustomerInfoDO();
    //      shopCustomerInfoDO.setAddress("shanghai");
    //      shopCustomerInfoDO.setApproveStatus(0);
    //      shopCustomerInfoDO.setBusinessLicense("c:/abc.jpg");
    //      shopCustomerInfoDO.setCity("shanghai");
    //      shopCustomerInfoDO.setDescription("testestsetsetsetset");
    //      shopCustomerInfoDO.setGmtCreate(new Date());
    //      shopCustomerInfoDO.setGoodsSource(1);
    //      shopCustomerInfoDO.setName("?aaa");
    //      shopCustomerInfoDO.setOpenDate(new Date());
    //      shopCustomerInfoDO.setOrganizationCode("c:/bcd.jpg");
    //      shopCustomerInfoDO.setProvince("shanghai");
    //      shopCustomerInfoDO.setSellerType(0);
    //      shopCustomerInfoDO.setShopCategory("1");
    //      shopCustomerInfoDO.setShopMark("c:/cde.jpg");
    //      shopCustomerInfoDO.setTitle("sdfsdf");
    //      shopCustomerInfoDO.setUserId(123);
    //      
    ////      try {
    ////         shopOpenAO.saveShopInfo(0, shopCustomerInfoDO);
    ////      } catch (ManagerException e) {
    ////         // TODO Auto-generated catch block
    ////         e.printStackTrace();
    ////      }
    //      
    //      /**
    //       * C?
    //       */
    ////      try {
    ////         shopOpenAO.updateShopCustomerInfo(123, shopCustomerInfoDO);
    ////      } catch (ManagerException e) {
    ////         // TODO Auto-generated catch block
    ////         e.printStackTrace();
    ////      }
    //      
    //      /**
    //       * C?
    //       */
    ////      try {
    ////         List cList = (ArrayList)shopOpenAO.queryShopCustomerInfo(123);
    ////         log.info("query shop C list is ===== "+cList);
    ////         log.info("shop name is ====== "+ ((ShopCustomerInfoDO)cList.get(0)).getName());
    ////      } catch (ManagerException e) {
    ////         // TODO Auto-generated catch block
    ////         e.printStackTrace();
    ////      }
    //      
    //      /**
    //       * ?B?
    //       */
    //      ShopBusinessInfoDO shopBusinessInfoDO = new ShopBusinessInfoDO();
    //      shopBusinessInfoDO.setAddress("shanghai");
    //      shopBusinessInfoDO.setApproveStatus(0);
    //      shopBusinessInfoDO.setBusinessLicense("c:/abc.jpg");
    //      shopBusinessInfoDO.setCity("shanghai");
    //      shopBusinessInfoDO.setDescription("testestsetsetsetset");
    //      shopBusinessInfoDO.setGmtCreate(new Date());
    //      shopBusinessInfoDO.setGoodsSource(1);
    //      shopBusinessInfoDO.setName("?bbb");
    //      shopBusinessInfoDO.setOpenDate(new Date());
    //      shopBusinessInfoDO.setOrganizationCode("c:/bcd.jpg");
    //      shopBusinessInfoDO.setProvince("shanghai");
    //      shopBusinessInfoDO.setSellerType(0);
    //      shopBusinessInfoDO.setShopCategory("1");
    //      shopBusinessInfoDO.setShopMark("c:/cde.jpg");
    //      shopBusinessInfoDO.setTitle("sdfsdf");
    //      shopBusinessInfoDO.setUserId(222);
    //      shopBusinessInfoDO.setBrandCertificate("c:/123.jpg");
    //      shopBusinessInfoDO.setBrandEnglishName("aaa");
    //      shopBusinessInfoDO.setBrandLogo("asdf");
    //      shopBusinessInfoDO.setBrandName("??");
    //      shopBusinessInfoDO.setBusiness("asdf");
    //      shopBusinessInfoDO.setBusinessCertificate("asdfasdf");
    //      shopBusinessInfoDO.setBusinessLicense("c:/asdf.jpg");
    //      shopBusinessInfoDO.setBusinessLicenseEndDate(new Date());
    //      shopBusinessInfoDO.setBusinessLicenseNumber("1212121213333");
    //      shopBusinessInfoDO.setContactAddress("nanjin");
    //      shopBusinessInfoDO.setContactName("dfdfdfd");
    //      shopBusinessInfoDO.setContactPhone("66677788");
    //      shopBusinessInfoDO.setContactPostalCode("asfasdf");
    //      shopBusinessInfoDO.setEmergencyContactName("lm");
    //      shopBusinessInfoDO.setEmergencyContactPhone("77788899");
    //      shopBusinessInfoDO.setEnterpriseName("jj");
    //      shopBusinessInfoDO.setHygieneLicense("c:/asf.jpg");
    //      shopBusinessInfoDO.setLegalName("dfsadfasd");
    //      shopBusinessInfoDO.setOrganizationCodeNumber("12345");
    //      shopBusinessInfoDO.setProductionLicense("c:/asfsafsdf.jpg");
    //      shopBusinessInfoDO.setQualityCertificate("c:/asdf.jpg");
    //      shopBusinessInfoDO.setRegistAddress("asdfasdfasdfasdf");
    //      shopBusinessInfoDO.setShopManagerEmail("asdf");
    //      shopBusinessInfoDO.setShopManagerFax("332452345");
    //      shopBusinessInfoDO.setShopManagerMobile("1213343244");
    //      shopBusinessInfoDO.setShopManagerName("asdf");
    //      shopBusinessInfoDO.setShopManagerTelephone("14812984");
    //      shopBusinessInfoDO.setShopNature("asfasdf");
    //      shopBusinessInfoDO.setTrademarkNumber("1294128340");
    ////      try {
    ////         shopOpenAO.saveShopInfo(1, shopBusinessInfoDO);
    ////      } catch (ManagerException e) {
    ////         // TODO Auto-generated catch block
    ////         e.printStackTrace();
    ////      }
    //      
    //      /**
    //       * B?
    //       */
    ////      try {
    ////         shopOpenAO.updateShopBusinessInfo(222, shopBusinessInfoDO);
    ////      } catch (ManagerException e) {
    ////         // TODO Auto-generated catch block
    ////         e.printStackTrace();
    ////      }
    //      
    //      /**
    //       * B?
    //       */
    //      try {
    //         List bList = (ArrayList)shopOpenAO.queryShopBusinessInfo(100000055000000l);
    //         log.info("query shop B list is ===== "+bList);
    //         log.info("shop name is ====== "+ ((ShopBusinessInfoDO)bList.get(0)).getName());
    //      } catch (ManagerException e) {
    //         // TODO Auto-generated catch block
    //         e.printStackTrace();
    //      }
    ////      
    //      /**
    //       * ???
    //       */
    ////      ShopOpenFlowDO shopOpenFlowDO = new ShopOpenFlowDO();
    ////      shopOpenFlowDO.setAuditCount(1);
    ////      shopOpenFlowDO.setAuditDate(new Date());
    ////      shopOpenFlowDO.setAuditProgress("asfasdfasdfasdf");
    ////      shopOpenFlowDO.setAuditStatus(0);
    ////      shopOpenFlowDO.setIsAgreement(0);
    ////      shopOpenFlowDO.setIsBlack(0);
    ////      shopOpenFlowDO.setIsFillInfo(0);
    ////      shopOpenFlowDO.setIsKa(0);
    ////      shopOpenFlowDO.setSellerType(1);
    ////      shopOpenFlowDO.setUserId(12345);
    ////      shopOpenFlowDO.setIsOnlineAuditEnd(0);
    ////      shopOpenFlowDO.setIsPostalAuditEnd(0);
    ////      shopOpenFlowDO.setIsSampleAuditEnd(0);
    ////      shopOpenFlowDO.setNoPassReason("asdfasdfasdfasdf");
    ////      shopOpenFlowDO.setGmtCreate(new Date());
    ////      try {
    ////         shopOpenAO.saveShopOpenFlow(shopOpenFlowDO);
    ////      } catch (ManagerException e) {
    ////         // TODO Auto-generated catch block
    ////         e.printStackTrace();
    ////      }
    //      
    //      /**
    //       * ??
    //       */
    ////      ShopOpenFlowDO shopOpenFlowDO = new ShopOpenFlowDO();
    ////      shopOpenFlowDO.setAuditStatus(1);
    ////      shopOpenFlowDO.setIsOnlineAuditEnd(1);
    ////      shopOpenFlowDO.setUserId(555);
    ////      shopOpenFlowDO.setNoPassReason("??");
    ////      try {
    ////         shopOpenAO.updateShopOpenFlow(shopOpenFlowDO);
    ////      } catch (ManagerException e) {
    ////         // TODO Auto-generated catch block
    ////         e.printStackTrace();
    ////      }
    //      
    //      /**
    //       * ???
    //       */
    ////      try {
    ////         List flowList = (ArrayList)shopOpenAO.queryShopOpenFlow(222);
    ////         log.info("audit status is == "+((ShopOpenFlowDO)flowList.get(0)).getAuditStatus());
    ////      } catch (ManagerException e) {
    ////         // TODO Auto-generated catch block
    ////         e.printStackTrace();
    ////      }
    //      
    //      /**
    //       * ?????
    //       */
    ////      try {
    ////         Object back = shopOpenAO.agreement(222,1);
    ////         log.info(back+"====================");
    ////      } catch (ManagerException e) {
    ////         // TODO Auto-generated catch block
    ////         e.printStackTrace();
    ////      }
    //      
    //      
    //      
    //      ShopOpenFlowDO shopOpenFlowDO = new ShopOpenFlowDO();
    //      shopOpenFlowDO.setUserId((int)12345);
    //      shopOpenFlowDO.setIsAgreement(ShopConstant.IS_AGREEMENT_TRUE);
    //      shopOpenFlowDO.setSellerType(0);
    //      shopOpenFlowDO.setGmtCreate(new Date());
    //      shopOpenFlowDO.setAuditCount(1);
    //      shopOpenFlowDO.setAuditDate(new Date());
    //      shopOpenFlowDO.setAuditProgress("");
    //      shopOpenFlowDO.setAuditStatus(0);
    //      shopOpenFlowDO.setConfiguration("");
    //      shopOpenFlowDO.setIsBlack(0);
    //      shopOpenFlowDO.setIsFillInfo(0);
    //      shopOpenFlowDO.setIsKa(0);
    //      shopOpenFlowDO.setIsOnlineAuditEnd(0);
    //      shopOpenFlowDO.setIsPostalAuditEnd(0);
    //      shopOpenFlowDO.setNoPassReason("");
    //      shopOpenFlowDO.setReviewer("");
    //      try {
    //         Object back = shopOpenAO.agreement(shopOpenFlowDO);
    //         log.info(back);
    //      } catch (ManagerException e) {
    //         // TODO Auto-generated catch block
    //         e.printStackTrace();
    //      }

}

From source file:net.bioclipse.structuredb.business.StructuredbManager.java

private ApplicationContext createApplicationcontext(String databaseName, boolean local) {

    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(
            Structuredb.class.getClassLoader().getResource("applicationContext.xml").toString());

    BasicDataSource dataSource = (BasicDataSource) context.getBean("dataSource");

    if (local) {//from   www.j  a  v a2  s . com
        dataSource.setUrl(HsqldbUtil.getInstance().getConnectionUrl(databaseName + ".sdb"));
    } else {
        throw new UnsupportedOperationException("non-local databases not " + "supported in this version");
    }
    return context;
}

From source file:net.frontlinesms.FrontlineSMS.java

/** Initialise {@link #applicationContext}. */
public void initApplicationContext() throws DataAccessResourceFailureException {
    // Load the data mode from the app.properties file
    AppProperties appProperties = AppProperties.getInstance();

    LOG.info("Load Spring/Hibernate application context to initialise DAOs");

    // Create a base ApplicationContext defining the hibernate config file we need to import
    StaticApplicationContext baseApplicationContext = new StaticApplicationContext();
    baseApplicationContext.registerBeanDefinition("hibernateConfigLocations",
            createHibernateConfigLocationsBeanDefinition());

    // Get the spring config locations
    String databaseExternalConfigPath = ResourceUtils.getConfigDirectoryPath()
            + ResourceUtils.PROPERTIES_DIRECTORY_NAME + File.separatorChar
            + appProperties.getDatabaseConfigPath();
    String[] configLocations = getSpringConfigLocations(databaseExternalConfigPath);
    baseApplicationContext.refresh();/*from w w w  . j a  va 2s .  c  o  m*/

    FileSystemXmlApplicationContext applicationContext = new FileSystemXmlApplicationContext(configLocations,
            false, baseApplicationContext);
    this.applicationContext = applicationContext;

    // Add post-processor to handle substituted database properties
    PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
    String databasePropertiesPath = ResourceUtils.getConfigDirectoryPath()
            + ResourceUtils.PROPERTIES_DIRECTORY_NAME + File.separatorChar
            + appProperties.getDatabaseConfigPath() + ".properties";
    propertyPlaceholderConfigurer.setLocation(new FileSystemResource(new File(databasePropertiesPath)));
    propertyPlaceholderConfigurer.setIgnoreResourceNotFound(true);
    applicationContext.addBeanFactoryPostProcessor(propertyPlaceholderConfigurer);
    applicationContext.refresh();

    LOG.info("Context loaded successfully.");

    this.pluginManager = new PluginManager(this, applicationContext);

    LOG.info("Getting DAOs from application context...");
    groupDao = (GroupDao) applicationContext.getBean("groupDao");
    groupMembershipDao = (GroupMembershipDao) applicationContext.getBean("groupMembershipDao");
    contactDao = (ContactDao) applicationContext.getBean("contactDao");
    keywordDao = (KeywordDao) applicationContext.getBean("keywordDao");
    keywordActionDao = (KeywordActionDao) applicationContext.getBean("keywordActionDao");
    messageDao = (MessageDao) applicationContext.getBean("messageDao");
    emailDao = (EmailDao) applicationContext.getBean("emailDao");
    emailAccountDao = (EmailAccountDao) applicationContext.getBean("emailAccountDao");
    smsInternetServiceSettingsDao = (SmsInternetServiceSettingsDao) applicationContext
            .getBean("smsInternetServiceSettingsDao");
    smsModemSettingsDao = (SmsModemSettingsDao) applicationContext.getBean("smsModemSettingsDao");
    eventBus = (EventBus) applicationContext.getBean("eventBus");
}

From source file:org.openspaces.admin.application.ApplicationFileDeployment.java

private static ApplicationConfig readConfigFromXmlFile(final String applicationFilePath) throws BeansException {
    ApplicationConfig config;// w  w  w .j a  v  a  2 s . c o  m

    // Convert to URL to workaround the "everything is a relative paths problem"
    // see spring documentation 5.7.3 FileSystemResource caveats.
    String fileUri = new File(applicationFilePath).toURI().toString();
    final FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(fileUri);

    try {
        //CR: Catch runtime exceptions. convert to AdminException(s)
        context.refresh();
        config = context.getBean(ApplicationConfig.class);
    } finally {
        if (context.isActive()) {
            context.close();
        }
    }
    return config;
}

From source file:org.springframework.xd.gemfire.CacheServer.java

public static void main(String[] args) {
    if (args.length != 1) {
        System.out.println("Usage: CacheServer <config-file-path>");
        System.exit(1);/*from  www . j  a  va  2  s . c o m*/
    }
    String path = args[0];

    if (!portAvailable(port)) {
        System.out.println("Cache Server port " + port + " is not available. Is another instance running?");
        System.exit(1);
    }
    logger.info("Starting Cache Server");
    @SuppressWarnings("resource")
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(path);
    context.registerShutdownHook();
    Cache cache = context.getBean(Cache.class);
    ManagementService ms = ManagementService.getExistingManagementService(cache);
    CacheServerMXBean cacheServerManager = ms.getLocalCacheServerMXBean(port);
    if (!cacheServerManager.isRunning()) {
        System.out.println("failed to start cache server ");
        System.exit(1);
    }
    System.out.println("cache server running");
}

From source file:org.springframework.xd.gemfire.server.CacheServer.java

public static void main(String[] args) {
    if (args.length != 1) {
        System.out.println("Usage: CacheServer <config-file-path>");
        System.exit(1);/*www . j  a v a  2  s .  com*/
    }

    /*
     * Ensure absolute path is handled
     */
    String path = args[0];
    if (!path.startsWith("file:")) {
        path = "file:" + path;
    }

    if (!portAvailable(port)) {
        System.out.println("Cache Server port " + port + " is not available. Is another instance running?");
        System.exit(1);
    }
    logger.info("Starting Cache Server");
    @SuppressWarnings("resource")
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(path);
    context.registerShutdownHook();
    Cache cache = context.getBean(Cache.class);
    ManagementService ms = ManagementService.getExistingManagementService(cache);
    CacheServerMXBean cacheServerManager = ms.getLocalCacheServerMXBean(port);
    if (!cacheServerManager.isRunning()) {
        System.out.println("failed to start cache server ");
        System.exit(1);
    }
    System.out.println("cache server running");
}