public static void main(String args[]) throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "com/tutorial/spring/dao_02/_02JdbcTemplateDaoQueries/applicationContext.xml"); SelectInter select = (SelectInter) ctx.getBean("db"); /*System.out.println("Employee count with Clerk disgnation is: " + select.getEmpCount("AD_PRES")); */ Map m = select.getEmpDetails(100); System.out.println("Details of empno: 100 are: " + m.toString()); /*System.out.println("Clerk designation employees details are: "); List l = select.getEmpDetails("AD_VP"); for (int i = 0; i < l.size(); i++) { Map m1 = (Map) l.get(i); System.out.println(m1.toString()); }*/ // boolean bool = s.registerEmp(1, "Manoj", "MANAGER", 50000); // System.out.println("Employee registered "+bool); // bool = s.modifyDesignation(1, "PRESIDENT"); // System.out.println("Employee designation updated "+bool); // Thread.sleep(5000); // bool = s.fireEmp(1); // System.out.println("Employee fired "+bool); }
public static void main(String[] args) { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("AC-test.xml"); IRuleEngine ruleEngine = ctx.getBean("ruleEngine", IRuleEngine.class); System.out.println(ruleEngine.getRulePackages()); // ruleEngine.execute("p2", "1"); PremiumCalcBom bom = new PremiumCalcBom(); bom.setInsuredSex("F"); bom.setInsPeriodUnit("Y"); bom.setInsPeriod("10"); bom.setPayMode("T"); bom.setAmount(10000.0); bom.setInsuredBirthday("1990-01-01"); System.out.println("start"); StopWatch sw = new StopWatch(); sw.start(); // for (int j = 0; j < 10000; j++) { for (int i = 80; i < 90; i++) { bom.setInsuredBirthday("19" + i + "-01-01"); int r = ruleEngine.execute("com.enci.ecp.bizprocess.product.rule.premiumcalc_00177000", bom); // System.out.println(bom.getTotalPremium()); } // } sw.stop(); System.out.println(sw.prettyPrint()); }
public void run() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); EmployeeManager employeeManager = context.getBean(EmployeeManagerImpl.class); ProjectManager projectManager = context.getBean(ProjectManagerImpl.class); UnitManager unitManager = context.getBean(UnitManagerImpl.class); Employee employeeOleksii = createEmployee("Junior Java Developer", "Oleksii", EmployeeStatus.NIIGER, 27); Employee employeeXZ = createEmployee("Middle Java Developer", "XZ", EmployeeStatus.NIIGER, 27); Long employeeOleksiiID = employeeManager.save(employeeOleksii); Long employeeXZID = employeeManager.save(employeeXZ); logger.info("Employee Oleksii saved with ID: " + employeeOleksiiID); logger.info("Employee XZ saved with ID: " + employeeXZID); // Project project = createProject(); Long projectID = projectManager.save(project); logger.info("Project CTrack saved with ID: " + projectID); Unit unit = createUnit(); Long unitID = unitManager.save(unit); logger.info("Unit CTrack saved with ID: " + unitID); employeeManager.addToUnit(employeeOleksiiID, unitID); employeeManager.addToUnit(employeeXZID, unitID); logger.info("Employee with ID: " + employeeOleksiiID + " added to Unit with ID: " + unitID); logger.info("Employee with ID: " + employeeXZID + " added to Unit with ID: " + unitID); employeeManager.assignToProject(employeeOleksiiID, projectID); logger.info( "Employee with ID: " + employeeOleksiiID + " assigned to Project with ID: " + projectID); // close resources context.close(); }
private static ClassPathXmlApplicationContext setup() { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-configs/config.xml"); applicationContext.registerShutdownHook(); applicationContext.start(); return applicationContext; }
public void testRemovingListeners() throws Exception { TestSubscriptionEventBean subscriptionBean = (TestSubscriptionEventBean) context.getBean("testSubscribingEventBean1"); assertNotNull(subscriptionBean); MuleEventMulticaster multicaster = (MuleEventMulticaster) context.getBean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME); assertNotNull(multicaster); Latch whenFinished = new Latch(); subscriptionBean.setEventCallback(new CountingEventCallback(eventCounter1, 1, whenFinished)); multicaster.removeApplicationListener(subscriptionBean); MuleClient client = new MuleClient(); client.send("vm://event.multicaster", "Test Spring Event", null); assertEquals(0, eventCounter1.get()); multicaster.addApplicationListener(subscriptionBean); client.send("vm://event.multicaster", "Test Spring Event", null); assertTrue(whenFinished.await(3000, TimeUnit.MILLISECONDS)); assertEquals(1, eventCounter1.get()); eventCounter1.set(0); multicaster.removeAllListeners(); client.send("vm://event.multicaster", "Test Spring Event", null); assertEquals(0, eventCounter1.get()); multicaster.addApplicationListener(subscriptionBean); context.refresh(); subscriptionBean.setEventCallback(null); }
public static void main(String[] args) { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("/mon/spring-http.xml", "spring-orac.xml"); final EventBus eventBus = applicationContext.getBean("eventBus", EventBus.class); eventBus.register(new BothSub()); eventBus.start(); /* final CountDownLatch countDownLatch = new CountDownLatch(1); for (int i = 0; i < 10 ; i++) { new Thread(new Runnable() { @Override public void run() { try { countDownLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } for (int a = 0; a < 10 ; a++) { int v = a % 3; if(a % 3 != 0 ) { Threads.sleep(1000 * v); } eventBus.publish(new EventA());//发送事件消息 } } }).start(); } countDownLatch.countDown();*/ }
public static void main(String[] args) throws Exception { String config = CacheProvider.class.getPackage().getName().replace('.', '/') + "/cache-provider.xml"; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config); context.start(); System.in.read(); }
@Override public void setUp() throws Exception { super.setUp(); this.fileFolderService = (FileFolderService) ctx.getBean("FileFolderService"); this.repositoryHelper = (Repository) ctx.getBean("repositoryHelper"); this.nodeService = (NodeService) ctx.getBean("NodeService"); this.transactionService = (TransactionService) ctx.getBean("transactionService"); server.setServletAuthenticatorFactory(new LocalTestRunAsAuthenticatorFactory()); NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome(); String guid = GUID.generate(); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); folderWithoutAspect = fileFolderService .create(companyHomeNodeRef, "folder_" + guid, ContentModel.TYPE_FOLDER) .getNodeRef(); assertNotNull("Doesn't create folder", folderWithoutAspect); folderWithAspect = fileFolderService .create(companyHomeNodeRef, "folder_aspect_" + guid, ContentModel.TYPE_FOLDER) .getNodeRef(); assertNotNull("Doesn't create folder", folderWithoutAspect); // add 'dublincore' aspect Map<QName, Serializable> aspectProps = new HashMap<QName, Serializable>(1); aspectProps.put(ContentModel.PROP_SUBJECT, "Test subject"); nodeService.addAspect(folderWithAspect, ContentModel.ASPECT_DUBLINCORE, aspectProps); }
// Option : standalone without webserver private void applyOptionWithoutWebServer() { // ApplicationContext initiliazed by DispatcherServlet otherwise applicationContext = new ClassPathXmlApplicationContext(); if (cmd.hasOption(OPTION_BACKEND)) { if (cmd.getOptionValue(OPTION_BACKEND).equalsIgnoreCase(Backend.MONGODB.toString())) applicationContext.getEnvironment().setActiveProfiles("standalone", "chart-mongodb"); else if (cmd.getOptionValue(OPTION_BACKEND).equalsIgnoreCase(Backend.RRD.toString())) applicationContext.getEnvironment().setActiveProfiles("standalone", "chart-rrd"); else { logger.info( "Unknown backend " + cmd.getOptionValue(OPTION_BACKEND) + ". You can choose between " + getBackends() + "."); System.exit(-1); } } else applicationContext.getEnvironment().setActiveProfiles("standalone", "chart-jpa"); // Init Spring controller applicationContext.setConfigLocations( new String[] { "classpath:applicationContext.xml", "classpath:applicationContext-jmx.xml", "classpath:applicationContext-jmx-standalone.xml", "classpath:applicationContext-jpa.xml", "classpath:applicationContext-mongodb.xml", "classpath:applicationContext-rrd.xml" }); ((ConfigurableApplicationContext) applicationContext).registerShutdownHook(); applicationContext.refresh(); }
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"classpath:/applicationContext-city.xml"}); RedisClient redisClient = context.getBean(RedisClient.class); redisClient.testGetPolicyVersion(); }
public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:ApplicationContext.xml"); SqlSessionTemplate template = applicationContext.getBean("sqlSessionTemplate", SqlSessionTemplate.class); FileInputStream stream = new FileInputStream(new File("/Users/yanzhao/Desktop/gg.html")); InputStreamReader reader = new InputStreamReader(stream, "utf-8"); BufferedReader bufferedReader = new BufferedReader(reader); String line = null; Map<String, Content> map = new HashMap<String, Content>(); List<String>[] tcodes = new List[10]; while ((line = bufferedReader.readLine()) != null) { String[] params = line.split(" "); Basedata basedata = new Basedata(); basedata.setCode(params[2]); basedata.setLink(params[0]); basedata.setName(params[1]); basedata.setZs(Long.parseLong(params[4])); basedata.setZsabbre(params[3]); System.out.println(JSON.toJSON(basedata)); template.insert("mybatis/mapper.BasedataMapper.insert", basedata); } }
static { if (fixDataSource == null) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {QATEST_DATASOURCE_PATH}); fixDataSource = (FixDataSource) context.getBean("fixDataSource"); } }
private static void initializeConnection() { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml"); if (applicationContext != null) { DB_CONNECTOR = (CouchDbConnector) applicationContext.getBean("osloPortalenDatabase"); } }
@Before public void setup() { _context = new ClassPathXmlApplicationContext("metering-vnxfile-context.xml"); try { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/dbutils-conf.xml"); _dbClient = (DbClientImpl) ctx.getBean("dbclient"); _dbClient = Cassandraforplugin.returnDBClient(); final TenantOrg tenantorg = new TenantOrg(); tenantorg.setId(URIUtil.createId(TenantOrg.class)); tenantorg.setLabel("some org"); tenantorg.setParentTenant( new NamedURI(URIUtil.createId(TenantOrg.class), tenantorg.getLabel())); _logger.info("TenantOrg :" + tenantorg.getId()); _dbClient.persistObject(tenantorg); final Project proj = new Project(); proj.setId(URIUtil.createId(Project.class)); proj.setLabel("some name"); proj.setTenantOrg(new NamedURI(tenantorg.getId(), proj.getLabel())); _logger.info("Project :" + proj.getId()); _logger.info("TenantOrg-Proj :" + proj.getTenantOrg()); _dbClient.persistObject(proj); final FileShare fileShare = new FileShare(); fileShare.setId(URIUtil.createId(FileShare.class)); fileShare.setLabel("some fileshare"); fileShare.setNativeGuid("CELERRA+" + serialNumber); fileShare.setVirtualPool(URIUtil.createId(VirtualPool.class)); fileShare.setProject(new NamedURI(proj.getId(), fileShare.getLabel())); fileShare.setCapacity(12500L); _dbClient.persistObject(fileShare); } catch (final Exception ioEx) { _logger.error("Exception occurred while persisting objects in db {}", ioEx.getMessage()); _logger.error(ioEx.getMessage(), ioEx); } }
public static void main(String[] args) { ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(new String[] {"config.xml"}); Hello h = (Hello) ac.getBean("hello"); System.out.println(h.getWho() + ":"); h.sayHi(); }
@Test public void testMethodsIntercepted() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("test-class-path-scan-operation.xml", getClass()); assertNotNull("Cannot find " + Fubar.class.getSimpleName(), ctx.getBean(Fubar.class)); ArgumentCaptor<Operation> opCaptor = ArgumentCaptor.forClass(Operation.class); Mockito.verify(spiedOperationCollector, Mockito.atLeastOnce()).enter(opCaptor.capture()); final Package pkg = getClass().getPackage(); Map<String, String> locationsMap = new TreeMap<String, String>() { private static final long serialVersionUID = 1L; { put("findCandidateComponents", pkg.getName()); put( "findPathMatchingResources", "classpath*:" + pkg.getName().replace('.', '/') + "/**/*.class"); } }; for (Operation captured : opCaptor.getAllValues()) { Operation op = assertScanOperation(captured); SourceCodeLocation scl = op.getSourceCodeLocation(); String methodName = scl.getMethodName(); String expectedLocation = locationsMap.remove(methodName); assertNotNull("Unnown method: " + methodName, expectedLocation); String actualLocation = op.get(SpringLifecycleMethodOperationCollectionAspect.EVENT_ATTR, String.class); assertEquals(methodName + ": Mismatched location", expectedLocation, actualLocation); } assertTrue("Aspect did not intercept call to " + locationsMap.keySet(), locationsMap.isEmpty()); }
/** @param args the command line arguments */ public static void main(String args[]) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "xml/custom/collector-beans.xml", "xml/global/global-beans.xml", "xml/custom/swing.xml" }); final OPCClientGlance opcCollectorGlance = (OPCClientGlance) context.getBean("opcCollectorGlance"); java.awt.EventQueue.invokeLater( new Runnable() { public void run() { SelectOPCItemView dialog = new SelectOPCItemView( new javax.swing.JFrame(), null, true, opcCollectorGlance, 0, 0); dialog.addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); }
public static void main(String args[]) { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "SplunkInboundChannelAdapterSavedSample-context.xml", SplunkInboundChannelAdapterSavedSample.class); ctx.start(); }
public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath*:spring-*.xml"); context.start(); CountDownLatch countDownLatch = new CountDownLatch(1); countDownLatch.await(); }
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml"); Car c = (Car) context.getBean("carBean"); System.out.println(c); context.close(); }
/** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("provider.xml"); context.start(); System.out.println("dubbo监听中"); System.in.read(); // 按任意键退出 }
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationBeans.xml"); App main = context.getBean(App.class); main.run(); context.close(); }
public void testReceivingASpringEvent() throws Exception { TestApplicationEventBean bean = (TestApplicationEventBean) context.getBean("testEventSpringBean"); assertNotNull(bean); final Latch whenFinished = new Latch(); EventCallback callback = new EventCallback() { public void eventReceived(UMOEventContext context, Object o) throws Exception { assertNull(context); if (o instanceof TestApplicationEvent) { if (eventCounter1.incrementAndGet() == 1) { whenFinished.countDown(); } } } }; bean.setEventCallback(callback); context.publishEvent(new TestApplicationEvent(context)); whenFinished.await(3000, TimeUnit.MILLISECONDS); assertEquals(1, eventCounter1.get()); }
/** * Provides a static, single instance of the application context. This method can be called * repeatedly. * * <p>If the configuration requested differs from one used previously, then the previously-created * context is shut down. * * @return Returns an application context for the given configuration */ public static synchronized ApplicationContext getApplicationContext( String[] configLocations, String[] classLocations) throws IOException { if (configLocations == null) { throw new IllegalArgumentException("configLocations argument is mandatory."); } if (usedConfiguration != null && Arrays.deepEquals(configLocations, usedConfiguration) && classLocations != null && Arrays.deepEquals(classLocations, usedClassLocations)) { // The configuration was used to create the current context return instance; } // The config has changed so close the current context (if any) closeApplicationContext(); if (useLazyLoading || noAutoStart) { instance = new VariableFeatureClassPathXmlApplicationContext(configLocations); } else { instance = new ClassPathXmlApplicationContext(configLocations, false); } if (classLocations != null) { ClassLoader classLoader = buildClassLoader(classLocations); instance.setClassLoader(classLoader); } instance.refresh(); usedConfiguration = configLocations; usedClassLocations = classLocations; return instance; }
@Before public void Before() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); lampService = (LampService) context.getBean("lampService"); System.out.println(lampService); }
public static void main(String[] args) throws Throwable { // you can setup $GRIDGAIN_HOME as an environmental variable File whereImKeepingGridgain = new File(new File(SystemUtils.getUserHome(), "Desktop"), "gridgain-2.1.1"); System.setProperty("GRIDGAIN_HOME", whereImKeepingGridgain.getAbsolutePath()); ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("gridservice.xml"); applicationContext.registerShutdownHook(); applicationContext.start(); SalutationService salutationServiceImpl = (SalutationService) applicationContext.getBean("salutationService"); String[] names = ("Alan,Arin,Clark,Craig,Drew,Gary,Gordon,Fumiko," + "Hicham,Jordon,Kathy,Ken,Makani,Mario, " + "Mark,Mia,Mike,Nick,Richard,Richelle, " + "Rod,Ron,Scott,Shaun,Srinivas,Valerie,Venkatesh") .split(","); System.out.println(StringUtils.repeat("=", 100)); for (String name : names) { System.out.println("Result: " + salutationServiceImpl.saluteSomeoneInForeignLanguage(name)); } System.out.println(StringUtils.repeat("=", 100)); System.out.println( "Results:" + StringUtils.join( salutationServiceImpl.saluteManyPeopleInRandomForeignLanguage(names), ",")); }
@Test public void testAutowireByAutoDetect() throws IOException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("chapter3/autowire-autodetect.xml"); HelloApi helloApi = context.getBean("bean", HelloApi.class); helloApi.sayHello(); }
public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"provider.xml"}); context.start(); System.in.read(); // 按任意键退出 }
public void testSerializableWithoutPreviousUsage() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("annotationDrivenProxyTargetClassTests.xml", getClass()); TransactionalService service = context.getBean("service", TransactionalService.class); service = (TransactionalService) SerializationTestUtils.serializeAndDeserialize(service); service.setSomething("someName"); }
public static void main(String[] args) throws Exception { URL file = new URL("file:///Volumes/DATA/Dropbox/wdz/20131116-1130.DAD"); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("tangle-spring.xml"); SectionService service = ctx.getBean(DADSectionService.class); service.process(file, Interval.MIN5); }