List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext
public FileSystemXmlApplicationContext(String... configLocations) throws BeansException
From source file:com.buy.plugin.spring.SpringPlugin.java
public boolean start() { if (ctx != null) IocInterceptor.ctx = ctx;/*ww w . j a v a 2 s .co m*/ else if (configurations != null) IocInterceptor.ctx = new FileSystemXmlApplicationContext(configurations); else IocInterceptor.ctx = new FileSystemXmlApplicationContext( PathKit.getWebRootPath() + "/WEB-INF/applicationContext.xml"); return true; }
From source file:demo.config.ApplicationContextLoader.java
private ApplicationContextLoader() throws URISyntaxException { try {//from w w w .j av a 2s .co m this.appContext = new ClassPathXmlApplicationContext("beanContext.xml"); } catch (Exception e) { this.appContext = new FileSystemXmlApplicationContext("beanContext.xml"); } }
From source file:org.examproject.websocket.SpringWebSocketServlet.java
@Override public void init() throws ServletException { try {//from w w w . j a v a 2 s.c o m // trying to load the Spring context file. // it's declared in Servlet web.xml. ServletConfig sc = getServletConfig(); String configLocation = sc.getInitParameter("contextConfigLocation"); context = new FileSystemXmlApplicationContext( getServletContext().getRealPath("/") + "/" + configLocation); // must call the superclass init method. super.init(); } catch (ServletException se) { throw se; } catch (Exception e) { throw new ServletException(e); } }
From source file:com.yuwang.pinju.core.shop.ao.TestShopOpenAO.java
License:asdf
/** * ??//from ww w . j av a 2 s.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:org.apache.s4.client.Adapter.java
@SuppressWarnings("static-access") public static void main(String args[]) throws IOException, InterruptedException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c")); options.addOption(/* w w w . j a va2s . co m*/ OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i")); options.addOption( OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t")); options.addOption(OptionBuilder.withArgName("userconfig").hasArg() .withDescription("user-defined legacy data adapter configuration file").create("d")); CommandLineParser parser = new GnuParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (ParseException pe) { System.err.println(pe.getLocalizedMessage()); System.exit(1); } int instanceId = -1; if (commandLine.hasOption("i")) { String instanceIdStr = commandLine.getOptionValue("i"); try { instanceId = Integer.parseInt(instanceIdStr); } catch (NumberFormatException nfe) { System.err.println("Bad instance id: %s" + instanceIdStr); System.exit(1); } } if (commandLine.hasOption("c")) { coreHome = commandLine.getOptionValue("c"); } String configType = "typical"; if (commandLine.hasOption("t")) { configType = commandLine.getOptionValue("t"); } String userConfigFilename = null; if (commandLine.hasOption("d")) { userConfigFilename = commandLine.getOptionValue("d"); } File userConfigFile = new File(userConfigFilename); if (!userConfigFile.isFile()) { System.err.println("Bad user configuration file: " + userConfigFilename); System.exit(1); } File coreHomeFile = new File(coreHome); if (!coreHomeFile.isDirectory()) { System.err.println("Bad core home: " + coreHome); System.exit(1); } if (instanceId > -1) { System.setProperty("instanceId", "" + instanceId); } else { System.setProperty("instanceId", "" + S4Util.getPID()); } String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType; String configPath = configBase + File.separatorChar + "client-adapter-conf.xml"; File configFile = new File(configPath); if (!configFile.exists()) { System.err.printf("adapter config file %s does not exist\n", configPath); System.exit(1); } // load adapter config xml ApplicationContext coreContext; coreContext = new FileSystemXmlApplicationContext("file:" + configPath); ApplicationContext context = coreContext; Adapter adapter = (Adapter) context.getBean("client_adapter"); ApplicationContext appContext = new FileSystemXmlApplicationContext( new String[] { "file:" + userConfigFilename }, context); Map<?, ?> inputStubBeanMap = appContext.getBeansOfType(InputStub.class); Map<?, ?> outputStubBeanMap = appContext.getBeansOfType(OutputStub.class); if (inputStubBeanMap.size() == 0 && outputStubBeanMap.size() == 0) { System.err.println("No user-defined input/output stub beans"); System.exit(1); } ArrayList<InputStub> inputStubs = new ArrayList<InputStub>(inputStubBeanMap.size()); ArrayList<OutputStub> outputStubs = new ArrayList<OutputStub>(outputStubBeanMap.size()); // add all input stubs for (Map.Entry<?, ?> e : inputStubBeanMap.entrySet()) { String beanName = (String) e.getKey(); System.out.println("Adding InputStub " + beanName); inputStubs.add((InputStub) e.getValue()); } // add all output stubs for (Map.Entry<?, ?> e : outputStubBeanMap.entrySet()) { String beanName = (String) e.getKey(); System.out.println("Adding OutputStub " + beanName); outputStubs.add((OutputStub) e.getValue()); } adapter.setInputStubs(inputStubs); adapter.setOutputStubs(outputStubs); }
From source file:com.quartzdesk.executor.common.spring.SpringContext.java
/** * Returns the {@link SpringContext} instance wrapping a new application * context whose configuration is read from the specified file path. * * @param filePath an application context configuration file path. * @return the {@link SpringContext} instance wrapping the created * application context./* ww w . j a va 2s. c o m*/ */ public static SpringContext forFileSystemResource(String filePath) { return new SpringContext(new FileSystemXmlApplicationContext(filePath)); }
From source file:org.apache.smscserver.main.Daemon.java
/** * Get the configuration object./*from www . j a v a 2 s .c o m*/ */ private static SmscServer getConfiguration(String[] args) throws Exception { SmscServer server = null; if ((args == null) || (args.length < 2)) { Daemon.LOG.info("Using default configuration...."); server = new SmscServerFactory().createServer(); } else if ((args.length == 2) && args[1].equals("-default")) { // supported for backwards compatibility, but not documented System.out.println("The -default switch is deprecated, please use --default instead"); Daemon.LOG.info("Using default configuration...."); server = new SmscServerFactory().createServer(); } else if ((args.length == 2) && args[1].equals("--default")) { Daemon.LOG.info("Using default configuration...."); server = new SmscServerFactory().createServer(); } else if (args.length == 2) { Daemon.LOG.info("Using xml configuration file " + args[1] + "..."); FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(args[1]); if (ctx.containsBean("server")) { server = (SmscServer) ctx.getBean("server"); } else { String[] beanNames = ctx.getBeanNamesForType(SmscServer.class); if (beanNames.length == 1) { server = (SmscServer) ctx.getBean(beanNames[0]); } else if (beanNames.length > 1) { System.out .println("Using the first server defined in the configuration, named " + beanNames[0]); server = (SmscServer) ctx.getBean(beanNames[0]); } else { System.err.println("XML configuration does not contain a server configuration"); } } } else { throw new SmscException("Invalid configuration option"); } return server; }
From source file:org.accesointeligente.server.RobotContext.java
@Override public void contextInitialized(ServletContextEvent event) { try {// ww w . jav a 2 s . c o m context = new FileSystemXmlApplicationContext( event.getServletContext().getResource("/WEB-INF/robots.xml").toString()); logger.info("Context initialized"); } catch (Exception ex) { logger.error("Failed to initialize context", ex); } }
From source file:pt.esper.SpringManager.java
public void initialize() { System.out.println("Initializing SpringManager."); try {/* w w w . ja v a 2s.co m*/ applicationContext = new FileSystemXmlApplicationContext( new String[] { "src/main/resources/config/spring.xml" }); applicationContext.registerShutdownHook(); } catch (Exception e) { System.out.println("Exception while loading Application Context XML File: " + e.toString()); System.exit(1); } initialized = true; System.out.println("Initialized successfully"); }
From source file:com.spstudio.uc.level.one.TestBasicUseCase.java
@BeforeClass public static void setUpClass() { ApplicationContext factory = new FileSystemXmlApplicationContext( new String[] { "src/main/java/com/spstudio/common/config/spring-*.xml", "src/main/java/com/spstudio/modules/*/config/spring-*.xml" }); sessionFactory = (SessionFactory) factory.getBean("sessionFactory"); productService = (ProductService) factory.getBean("productService"); memeberService = (MemberService) factory.getBean("memberService"); salesService = (SaleService) factory.getBean("saleService"); workOrderService = (WorkOrderService) factory.getBean("workOrderService"); }