@Test public void testClassPathResource() { Resource cr = null; try { cr = new ClassPathResource("app-context.xml"); BeanFactory bf = new XmlBeanFactory(cr); // �Ѿ����� SayHello sayHello = (SayHello) bf.getBean("sayHello"); System.out.println(sayHello.toString()); } catch (Exception ex) { fail("error : " + ex.getMessage()); } finally { } Assert.assertFalse(false); }
public static void main(String argv[]) { Resource res1 = new ClassPathResource("onecmdb.xml"); XmlBeanFactory beanFactory1 = new XmlBeanFactory(res1); GenericApplicationContext svrctx1 = new GenericApplicationContext( beanFactory1); IOneCmdbContext ctx = (IOneCmdbContext) svrctx1.getBean("onecmdb"); ISession session = ctx.createSession(); // Startup Spring context. Resource res2 = new ClassPathResource("bean-provider-application.xml"); XmlBeanFactory beanFactory2 = new XmlBeanFactory(res2); GenericApplicationContext svrctx2 = new GenericApplicationContext( beanFactory2); BeanScope scope = (BeanScope) svrctx2.getBean("xmlToRfc"); scope.process(); ImportRfcs importRfcs = (ImportRfcs) svrctx2.getBean("rfcSender"); importRfcs.setSession(session); importRfcs.setRfcs(scope.getRFCs()); importRfcs.run(); }
public static IntegrationContextFactory lookup() throws Exception { // the instance is provided by Spring-injection if (useLocator) { SpringBeanLocator locator = SpringBeanLocator.getInstance(); return (IntegrationContextFactory) locator.getBean("integrationContextFactory"); } else // unit testing { Resource res = new ClassPathResource(CONFIGURATION); BeanFactory factory = new XmlBeanFactory(res); return (IntegrationContextFactory) factory.getBean("integrationContextFactory"); } }
public static SamigoApiFactory lookup() throws Exception { // the instance is provided by Spring-injection if (useLocator) { SpringBeanLocator locator = SpringBeanLocator.getInstance(); return (SamigoApiFactory) locator.getBean("samigoApiFactory"); } else // unit testing { Resource res = new ClassPathResource(CONFIGURATION); BeanFactory factory = new XmlBeanFactory(res); return (SamigoApiFactory) factory.getBean("samigoApiFactory"); } }
public static void main(String[] args) { // TODO Auto-generated method stub BeanFactory beanFactory=new XmlBeanFactory(new ClassPathResource("beans_classpath.xml")); BeanFactory beanFactory1=new XmlBeanFactory(new FileSystemResource("d:\\beans_fileSystem.xml")); System.out.println("beanfactory created successfully"); }
@Test public void testbean(){ Resource xmlResource = new FileSystemResource("jobs/profile-ltbot-default-seedfile/profile-crawler-beans-ltbot.cxml"); BeanFactory factory = new XmlBeanFactory(xmlResource); SentenceWriter w = (SentenceWriter)factory.getBean("sentenceWriterHtml"); SentenceMaker m = (SentenceMaker)factory.getBean("sentenceMaker"); }
private static void testXml() { ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource res = resolver.getResource("classpath:spring-context.xml"); BeanFactory bf = new XmlBeanFactory(res); System.out.println("init BeanFactory"); Mars mars = bf.getBean("mars", Mars.class); System.out.println(mars.getCnName() + ":" + mars.getAge()); }
public static ShardedJedisSentinelPool init() { // 初始化连接池 BeanFactory bf = new XmlBeanFactory(new ClassPathResource("applicationContext.xml")); ShardedJedisSentinelPool pool = bf.getBean("shardedJedisSentinelPool", ShardedJedisSentinelPool.class); System.out.println("init ShardedJedisSentinelPool success..."); return pool; }
public static void iocDoInstance() { // BeanFactory方式启动 ConfigurableListableBeanFactory beanFactory = new XmlBeanFactory( new ClassPathResource("spring.xml")); beanFactory.addBeanPostProcessor(new PasswordDecodePostProcessor()); DowJonesNewsListener newsListener = (DowJonesNewsListener) beanFactory .getBean("djNewsListener"); System.out.println(newsListener.getEncodedPassword()); // 容器退出之前,销毁singleton的实例 beanFactory.destroySingletons(); // 2.0,销毁实现 // ((AbstractApplicationContext)beanFactory).registerShutdownHook(); }
public static void iocStart() { // BeanFactory方式启动 ConfigurableListableBeanFactory beanFactory = new XmlBeanFactory( new ClassPathResource("spring.xml")); // 读取外部properties文件属性值填充xml中的bean,property PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer(); propertyPlaceholderConfigurer.setLocation(new ClassPathResource( "config.properties")); // 应用postProcessBeanFactory propertyPlaceholderConfigurer.postProcessBeanFactory(beanFactory); // 读取外部properties文件,覆盖xml中bean指定的property值 PropertyOverrideConfigurer propertyOverrideConfigurer = new PropertyOverrideConfigurer(); propertyOverrideConfigurer.setLocation(new ClassPathResource( "spring-adjustment.properties")); propertyOverrideConfigurer.postProcessBeanFactory(beanFactory); // CustomEditorConfigurer,对bean的property值,做类型转换支持 CustomEditorConfigurer customEditorConfigurer = new CustomEditorConfigurer(); Map customEditors = new HashMap(); customEditors.put(Date.class, new DatePropertyEditor()); customEditorConfigurer.setCustomEditors(customEditors); customEditorConfigurer.postProcessBeanFactory(beanFactory); FXNewsProvider newsProvider = (FXNewsProvider) beanFactory .getBean("newsProvider"); System.out.println(newsProvider.getClientId()); System.out.println(newsProvider.getBaseUrl()); System.out.println(newsProvider.getAddDate().toLocaleString()); }
public static BeanFactory bindViaXml(BeanDefinitionRegistry registry) { // XmlBeanDefinitionReader reader = new // XmlBeanDefinitionReader(registry); // reader.loadBeanDefinitions("classpath:/spring.xml"); // return (BeanFactory) registry; // 以上,等同于下句 return new XmlBeanFactory(new ClassPathResource("spring.xml")); }
private static XmlBeanFactory getBeanFactory() { File outerContextFile = new File(OUTER_APPLICATION_CONTEXT); boolean outerContextFileProper = outerContextFile.exists() && outerContextFile.isFile() && outerContextFile.canRead(); Resource res = (outerContextFileProper) ? new FileSystemResource( outerContextFile) : new ClassPathResource( INNER_APPLICATION_CONTEXT); return new XmlBeanFactory(res); }
/** * To initialize the beans. * @param <T> the type of beans to be created (for type safety in caller method). * @param context the context * @param res the resource containing new context information * @return initialized beans from definitions in {@code res} initialized with {@code context} */ public static <T> Map<String, T> initializeBeans(ConfigurableApplicationContext context, Resource res) { BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) context.getBeanFactory(); XmlBeanFactory factory = new XmlBeanFactory(res); String[] names = factory.getBeanDefinitionNames(); for (String name : names) { beanDefinitionRegistry.registerBeanDefinition(name, factory.getBeanDefinition(name)); } return getBeansFromContext(context, names); }
public void setUp() { // Resource res = new // ClassPathResource("org/onecmdb/core/example/application.xml"); Resource res = new ClassPathResource("application2.xml"); XmlBeanFactory beanFactory = new XmlBeanFactory(res); svrctx = new GenericApplicationContext(beanFactory); // PropertyPlaceholderConfigurer cfg = new // PropertyPlaceholderConfigurer(); // cfg.setLocation(new ClassPathResource("jdbc.properties")); // cfg.postProcessBeanFactory(beanFactory); final IOneCmdbContext cmdb = (IOneCmdbContext) svrctx .getBean("onecmdb"); session = cmdb.createSession(); IModelService cisvc = (IModelService) session .getService(IModelService.class); // well known name is ``root'' ciRoot = cisvc.getRoot(); assertNotNull(ciRoot); System.out.println(ciRoot.toString()); // Dump offsprings... System.out.println(dumpOffsprings(ciRoot, 0)); IReferenceService refSvc = (IReferenceService) session .getService(IReferenceService.class); ciRelationRoot = refSvc.getRootReference(); assertNotNull(ciRelationRoot); System.out.println(ciRelationRoot.toString()); }
public static void main(String argv[]) { // Startup Spring context. Resource res2 = new ClassPathResource("bean-provider-application.xml"); XmlBeanFactory beanFactory2 = new XmlBeanFactory(res2); GenericApplicationContext svrctx2 = new GenericApplicationContext( beanFactory2); BeanScope scope = (BeanScope) svrctx2.getBean("importer"); scope.process(); }
public void setUp() { // Resource res = new // ClassPathResource("org/onecmdb/core/example/application.xml"); Resource res = new ClassPathResource("onecmdb.xml"); XmlBeanFactory beanFactory = new XmlBeanFactory(res); GenericApplicationContext svrctx = new GenericApplicationContext( beanFactory); final IOneCmdbContext cmdb = (IOneCmdbContext) svrctx .getBean("onecmdb"); session = cmdb.createSession(); IModelService modelsvc = (IModelService) session .getService(IModelService.class); // well known name is ``root'' ICi root = modelsvc.getRoot(); assertNotNull(root); ICiService cisvc = (ICiService) session.getService(ICiService.class); // well known name is ``CI'' ciRoot = cisvc.getRootCi(); assertNotNull(ciRoot); IReferenceService refsvc = (IReferenceService) session .getService(IReferenceService.class); ciRelationRoot = refsvc.getRootReference(); assertNotNull(ciRelationRoot); }
public void setUp() { Resource res = new ClassPathResource("onecmdb.xml"); XmlBeanFactory beanFactory = new XmlBeanFactory(res); springctx = new GenericApplicationContext(beanFactory); onecmdb = (IOneCmdbContext) springctx.getBean("onecmdb"); }
public static void main(String[] args) { @SuppressWarnings("") BeanFactory bf = new XmlBeanFactory(new ClassPathResource("framework/c2/beanFactory.xml")); MyTestBean myTestBean = bf.getBean("myTestBean", MyTestBean.class); System.out.println(myTestBean.getTeststr()); }
public void testXmlBeanFactory(){ XmlBeanFactory beanFactory= new XmlBeanFactory(new ClassPathResource("src/main/resources/spring-chapt2.xml")); TestBean testBean = beanFactory.getBean("testBean",TestBean.class); testBean.hello(); testBean = beanFactory.getBean("abcbean",TestBean.class); testBean.hello(); testBean = beanFactory.getBean("abean",TestBean.class); testBean.hello(); }
protected TimexTestCase() { FileSystemResource res = new FileSystemResource("src/conf/timex2-servlet.xml"); springFactory = new XmlBeanFactory(res); departmentManager = (DepartmentManager)springFactory.getBean("departmentManagerProxy"); employeeManager = (EmployeeManager)springFactory.getBean("employeeManagerProxy"); timesheetManager = (TimesheetManager)springFactory.getBean("timesheetManagerProxy"); applicationSecurityManager = (ApplicationSecurityManager)springFactory.getBean("applicationSecurityManager"); }
public static void main(String[] args) { BeanFactory ctxStatic = new XmlBeanFactory( new ClassPathResource("com/springtraining/beanref/staticbeans.xml")); ConfigurableBeanFactory parent = new XmlBeanFactory( new ClassPathResource("com/springtraining/beanref/projectConfig.xml"),ctxStatic); ConfigurableBeanFactory child = new XmlBeanFactory( new ClassPathResource("com/springtraining/beanref/childConfig.xml")); child.setParentBeanFactory(parent); Payment pmt = (Payment) child.getBean("pmnt"); pmt.pay(); }
public synchronized static SessionFactory getSessionFactoryByDsName(String dataSourceName) { Map map = (Map) SessionContext.getAttributeForServletContext(SESSIONFACTORY); if (map == null) { SessionContext.setAttributeForServletContext(SESSIONFACTORY, new HashMap()); map = (Map) SessionContext.getAttributeForServletContext(SESSIONFACTORY); } SessionFactory sessionFactory = (SessionFactory) map.get(dataSourceName); if (sessionFactory == null) { try { DocumentBuilderFactory dbf = new org.apache.xerces.jaxp.DocumentBuilderFactoryImpl(); DocumentBuilder db = dbf.newDocumentBuilder(); db.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) throws IOException, SAXException { InputSource inputsource = new InputSource(); inputsource.setByteStream(XmlBeanFactory.class.getResource("spring-beans.dtd").openStream()); return inputsource; } }); String path = ServerBeanFactoryUtils.getApplicationContext().getServletContext().getRealPath(""); String initParameter = ServerBeanFactoryUtils.getApplicationContext().getServletContext().getInitParameter("contextConfigLocation"); String res[] = initParameter.split(" "); for(String r : res) { if(r.contains("applicationContext")){ path = path + r; break; } } Document doc = db.parse(path); NodeList list = (NodeList) doc.getElementsByTagName("list"); NodeList values = ((Element) list.item(0)).getElementsByTagName("value"); String[] hbm = new String[values.getLength()]; for (int i = 0; i < hbm.length; i++) { hbm[i] = values.item(i).getFirstChild().getNodeValue(); } LocalSessionFactoryBean bean = new LocalSessionFactoryBean(); bean.setDataSource(DataSourceUtils.findDataSource(dataSourceName)); bean.setMappingResources(hbm); Properties porp = new Properties(); porp.setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect"); porp.setProperty("hibernate.show_sql", "true"); porp.setProperty("hibernate.generate_statistics", "ture"); bean.setHibernateProperties(porp); bean.afterPropertiesSet(); sessionFactory = (SessionFactory) bean.getObject(); map.put(dataSourceName,sessionFactory); } catch (Exception e) { e.printStackTrace(); } } return sessionFactory; }
public static BeanFactory iocInit() { return new XmlBeanFactory(new ClassPathResource("spring.xml")); }
public static BeanFactory beanIocStart() { return new XmlBeanFactory(new ClassPathResource("spring.xml")); }
/** * Creates new instance of configuration helper with given configuration. * * @param factory Configuration factory. */ GridUriDeploymentSpringDocument(XmlBeanFactory factory) { assert factory != null; this.factory = factory; }
public Map<String, Object> deserialize(final String content) { DefaultListableBeanFactory beanfactory = new XmlBeanFactory(new Resource() { public long contentLength() throws IOException { // TODO Auto-generated method stub return 0; } public Resource createRelative(String relativePath) throws IOException { throw notSupported(); } public boolean exists() { return false; } public String getDescription() { return null; } public File getFile() throws IOException { throw notSupported(); } public String getFilename() { return null; } public InputStream getInputStream() throws IOException { StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); sb.append("<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN 2.0//EN\" \"http://www.springframework.org/dtd/spring-beans-2.0.dtd\">"); sb.append("<beans default-lazy-init=\"true\">"); sb.append(content); sb.append("</beans>"); return new ByteArrayInputStream(sb.toString().getBytes(Charsets.UTF_8)); } public URI getURI() throws IOException { throw notSupported(); } public URL getURL() throws IOException { throw notSupported(); } public boolean isOpen() { return false; } public boolean isReadable() { return false; } public long lastModified() throws IOException { return -1; } private IOException notSupported() { return new IOException("not supported"); } }); Map<String, Object> result = new HashMap<String, Object>(); for (String beanName : beanfactory.getBeanDefinitionNames()) { result.put(beanName, beanfactory.getBean(beanName)); } return result; }
public static BrineFreezingDao createBrineFreezingDao() { BeanFactory bf = new XmlBeanFactory(new ClassPathResource("dao-beans.xml")); return (BrineFreezingDao) bf.getBean("BrineFreezingDao"); }
public static FishBadStockDetailDao createFishBadStockDetailDao() { BeanFactory bf = new XmlBeanFactory(new ClassPathResource("dao-beans.xml")); return (FishBadStockDetailDao) bf.getBean("FishBadStockDetailDao"); }
public static PtsDtlDao createPtsDtlDao() { BeanFactory bf = new XmlBeanFactory(new ClassPathResource("dao-beans.xml")); return (PtsDtlDao) bf.getBean("PtsDtlDao"); }
public static FishRrDao createFishRrDao() { BeanFactory bf = new XmlBeanFactory(new ClassPathResource("dao-beans.xml")); return (FishRrDao) bf.getBean("FishRrDao"); }
public void init() { ClassPathResource res = new ClassPathResource("conf/beans.xml"); factory = new XmlBeanFactory(res); }
public static AssignCanvasserDtlDao createAssignCanvasserDtlDao() { BeanFactory bf = new XmlBeanFactory(new ClassPathResource("dao-beans.xml")); return (AssignCanvasserDtlDao) bf.getBean("AssignCanvasserDtlDao"); }
/** * */ public static AppMenuGroupDao createAppMenuGroupDao() { BeanFactory bf = new XmlBeanFactory(new ClassPathResource("dao-beans.xml")); return (AppMenuGroupDao) bf.getBean("AppMenuGroupDao"); }
public static FGPalletTransferDao createFGPalletTransferDao() { BeanFactory bf = new XmlBeanFactory(new ClassPathResource("dao-beans.xml")); return (FGPalletTransferDao) bf.getBean("FGPalletTransferDao"); }