當前位置: 首頁>>代碼示例>>Java>>正文


Java BeanFactory.getBean方法代碼示例

本文整理匯總了Java中org.springframework.beans.factory.BeanFactory.getBean方法的典型用法代碼示例。如果您正苦於以下問題:Java BeanFactory.getBean方法的具體用法?Java BeanFactory.getBean怎麽用?Java BeanFactory.getBean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.beans.factory.BeanFactory的用法示例。


在下文中一共展示了BeanFactory.getBean方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: saveXmallContext

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
/**
 * 保存 XmallContext 信息
 *
 * @param request
 */
private void saveXmallContext(HttpServletRequest request) {
    // 1.從 request 的 Header 頭中讀出 token
    String token = request.getHeader(XMALL_TOKEN);
    if (StringUtils.isBlank(token)) {
        logger.error("===> Request Header no token : xmall-Token");
        return;
    }
    logger.info("===> xmall-Token : {}", token);

    if (iUserService == null) { //解決service為null無法注入問題
        logger.error("===> iUserService is null!!!");
        BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext());
        iUserService = (IUserService) factory.getBean("iUserService");
    }

    // 2.將 token 取出 user 登錄對象
    ServerResponse<User> response = iUserService.getUser(token);
    if (response.isSuccess()) {
        User user = response.getData();
        // 3.將 user 對象寫入 context
        XmallContext context = XmallContext.getContext();
        context.setLoginUser(user);
    }
}
 
開發者ID:jeikerxiao,項目名稱:X-mall,代碼行數:30,代碼來源:MallInterceptor.java

示例2: jTable1FocusGained

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
private void jTable1FocusGained(java.awt.event.FocusEvent evt) {
BeanFactory factory = new DataBaseDataSource().getDataFactory();
 registrationDAO = (RegistrationDAO) factory
		.getBean("registrationDAO");
jList1.setModel(new javax.swing.AbstractListModel() {
	String[] strings = registrationDAO.viewFileName(users.getUserid()).split(",");

	public int getSize() {
		return strings.length;
	}

	public Object getElementAt(int i) {
		return strings[i];
	}
});
jScrollPane2.setViewportView(jList1);	}
 
開發者ID:cyberheartmi9,項目名稱:Mona-Secure-Multi-Owner-Data-Sharing-for-Dynamic-Group-in-the-Cloud,代碼行數:17,代碼來源:UserForm.java

示例3: qualifiedBeanOfType

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
/**
 * Obtain a bean of type {@code T} from the given {@code BeanFactory} declaring a
 * qualifier (e.g. via {@code <qualifier>} or {@code @Qualifier}) matching the given
 * qualifier, or having a bean name matching the given qualifier.
 * @param beanFactory the BeanFactory to get the target bean from
 * @param beanType the type of bean to retrieve
 * @param qualifier the qualifier for selecting between multiple bean matches
 * @return the matching bean of type {@code T} (never {@code null})
 * @throws NoSuchBeanDefinitionException if no matching bean of type {@code T} found
 */
public static <T> T qualifiedBeanOfType(BeanFactory beanFactory, Class<T> beanType, String qualifier) {
	if (beanFactory instanceof ConfigurableListableBeanFactory) {
		// Full qualifier matching supported.
		return qualifiedBeanOfType((ConfigurableListableBeanFactory) beanFactory, beanType, qualifier);
	}
	else if (beanFactory.containsBean(qualifier)) {
		// Fallback: target bean at least found by bean name.
		return beanFactory.getBean(qualifier, beanType);
	}
	else {
		throw new NoSuchBeanDefinitionException(qualifier, "No matching " + beanType.getSimpleName() +
				" bean found for bean name '" + qualifier +
				"'! (Note: Qualifier matching not supported because given " +
				"BeanFactory does not implement ConfigurableListableBeanFactory.)");
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:BeanFactoryAnnotationUtils.java

示例4: jButton3ActionPerformed

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
	BeanFactory factory = new DataBaseDataSource().getDataFactory();
	registrationDAO = (RegistrationDAO) factory.getBean("registrationDAO");
	Object obj[][] = registrationDAO.viewCloudFiles(users.getUserid());
	Object string[] = registrationDAO.viewCloudMetaData();
	new CloudServerWindow().setVisible(true);

	jList1.setModel(new javax.swing.AbstractListModel() {
		String[] strings = registrationDAO.viewFileName(users.getUserid())
				.split(",");

		public int getSize() {
			return strings.length;
		}

		public Object getElementAt(int i) {
			return strings[i];
		}
	});
}
 
開發者ID:cyberheartmi9,項目名稱:Mona-Secure-Multi-Owner-Data-Sharing-for-Dynamic-Group-in-the-Cloud,代碼行數:21,代碼來源:UserForm.java

示例5: setValue

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
@Override
public void setValue(ELContext elContext, Object base, Object property, Object value) throws ELException {
	if (base == null) {
		String beanName = property.toString();
		BeanFactory bf = getBeanFactory(elContext);
		if (bf.containsBean(beanName)) {
			if (value == bf.getBean(beanName)) {
				// Setting the bean reference to the same value is alright - can simply be ignored...
				elContext.setPropertyResolved(true);
			}
			else {
				throw new PropertyNotWritableException(
						"Variable '" + beanName + "' refers to a Spring bean which by definition is not writable");
			}
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:SpringBeanELResolver.java

示例6: jButton1ActionPerformed

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
	String groupname = jComboBox1.getSelectedItem().toString();
	if (!groupname.equals(users.getGroupname())) {
		BeanFactory beanFactory = new DataBaseDataSource().getDataFactory();
		RegistrationDAO registrationDAO = (RegistrationDAO) beanFactory
				.getBean("registrationDAO");
		users.setNewgroupname(groupname);
		System.out.println(groupname);
		boolean b = registrationDAO.usergroupcount(users);
		File f = new File("groups");
		boolean delete = f.delete();
		System.out.println("file deleted " + delete);
		new GroupMemberchange(users).setVisible(true);

	} else {

	}

}
 
開發者ID:cyberheartmi9,項目名稱:Mona-Secure-Multi-Owner-Data-Sharing-for-Dynamic-Group-in-the-Cloud,代碼行數:20,代碼來源:GroupMemberchange.java

示例7: wrap

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
/**
 * @param slice
 * @param beanFactory
 * @return
 */
public static SolrStoreMappingWrapper wrap(List<ShardInstance> slice, BeanFactory beanFactory)
{
    HttpClientFactory httpClientFactory = (HttpClientFactory)beanFactory.getBean("solrHttpClientFactory");
    for(ShardInstance instance : slice)
    {
        Pair<String, Integer> key = new Pair<String, Integer>(instance.getHostName(), instance.getPort());
        if(!clients.contains(key))
        {
            clients.put(key, httpClientFactory.getHttpClient(key.getFirst(), key.getSecond()));
        }
    }
    
    return new DynamicSolrStoreMappingWrapper(slice);
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:20,代碼來源:DynamicSolrStoreMappingWrapperFactory.java

示例8: autowireResource

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
/**
 * Obtain a resource object for the given name and type through autowiring
 * based on the given factory.
 * @param factory the factory to autowire against
 * @param element the descriptor for the annotated field/method
 * @param requestingBeanName the name of the requesting bean
 * @return the resource object (never {@code null})
 * @throws BeansException if we failed to obtain the target resource
 */
protected Object autowireResource(BeanFactory factory, LookupElement element, String requestingBeanName)
		throws BeansException {

	Object resource;
	Set<String> autowiredBeanNames;
	String name = element.name;

	if (this.fallbackToDefaultTypeMatch && element.isDefaultName &&
			factory instanceof AutowireCapableBeanFactory && !factory.containsBean(name)) {
		autowiredBeanNames = new LinkedHashSet<String>();
		resource = ((AutowireCapableBeanFactory) factory).resolveDependency(
				element.getDependencyDescriptor(), requestingBeanName, autowiredBeanNames, null);
	}
	else {
		resource = factory.getBean(name, element.lookupType);
		autowiredBeanNames = Collections.singleton(name);
	}

	if (factory instanceof ConfigurableBeanFactory) {
		ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) factory;
		for (String autowiredBeanName : autowiredBeanNames) {
			if (beanFactory.containsBean(autowiredBeanName)) {
				beanFactory.registerDependentBean(autowiredBeanName, requestingBeanName);
			}
		}
	}

	return resource;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:39,代碼來源:CommonAnnotationBeanPostProcessor.java

示例9: get

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
/**
 * Return the {@link JpaEntityScanPackages} for the given bean factory.
 * @param beanFactory the source bean factory
 * @param dataContextId Data context id
 * @return the {@link JpaEntityScanPackages} for the bean factory (never {@code null})
 */
public static JpaEntityScanPackages get(BeanFactory beanFactory, String dataContextId) {
	try {
		return beanFactory.getBean(buildBeanName(dataContextId), JpaEntityScanPackages.class);
	} catch (@SuppressWarnings("unused") NoSuchBeanDefinitionException ex) {
		return NONE;
	}
}
 
開發者ID:holon-platform,項目名稱:holon-datastore-jpa,代碼行數:14,代碼來源:JpaEntityScanPackages.java

示例10: getTenantResolver

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
/**
 * Get the {@link TenantResolver} to use from context
 * @return TenantResolver
 */
private TenantResolver getTenantResolver() {
	BeanFactory factory = beanFactory.get();
	if (factory == null) {
		throw new IllegalStateException("A beanFactory is not available");
	}
	return factory.getBean(TenantResolver.class);
}
 
開發者ID:holon-platform,項目名稱:holon-core,代碼行數:12,代碼來源:TenantScope.java

示例11: getBeanByNameOrType

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
public static <T> T getBeanByNameOrType(BeanFactory beanFactory, String name, Class<T> requiredType) {
    if (StringUtils.isEmpty(name)) {
        return beanFactory.getBean(requiredType);
    } else {
        return beanFactory.getBean(name, requiredType);
    }
}
 
開發者ID:cybozu,項目名稱:spring-data-jdbc-template,代碼行數:8,代碼來源:BeanFactoryUtils.java

示例12: main

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
public static void main(String[] args) {
    String[] resources = new String[]{"classpath*:applicationContext-dubbo-consumer.xml"};
    BeanFactory factory = new ClassPathXmlApplicationContext(resources);
    UserService userService = (UserService)factory.getBean("userService");
    UserExample userExample = new UserExample();
    userExample.createCriteria().andIdEqualTo("lisi");
    List<User> list = userService.selectByExample(userExample);
    for (User bean: list) {
        System.out.println(bean.toString());
    }
}
 
開發者ID:lgpzjp,項目名稱:rure,代碼行數:12,代碼來源:UserServiceTest.java

示例13: ceshi

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
@Test
public void ceshi(){
    DemoUser user = new DemoUser();
    user.setUsername("abc");
    user.setPassword(MD5Util.MD5("abc"));
    user.setSex(1);
    user.setCrtime(StringUtil.Date2String());

    String[] resources = new String[]{"classpath*:/dubbo-consumer.xml"  ,"classpath*:/META-INF/spring/applicationContext-jdbc.xml"};
    BeanFactory factory = new ClassPathXmlApplicationContext(resources);
    demoUserService = (DemoUserService)factory.getBean("demoUserService");
    DemoUser result = demoUserService.createUser(user);
    System.out.println(result);
}
 
開發者ID:lgpzjp,項目名稱:rure,代碼行數:15,代碼來源:DemoUserServiceTest.java

示例14: main

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
public static void main(String[] args) {
    String[] resources = new String[]{"classpath*:/spring-dubbo-consumer.xml"};
    BeanFactory factory = new ClassPathXmlApplicationContext(resources);
    DemoUserService demoUserService = (DemoUserService)factory.getBean("demoUserService");
    int result = demoUserService.selectDemoUserCount();
    System.out.println(result);
}
 
開發者ID:lgpzjp,項目名稱:rure,代碼行數:8,代碼來源:DemoMain.java

示例15: MainFrame

import org.springframework.beans.factory.BeanFactory; //導入方法依賴的package包/類
/** Creates new form MainFrame */
public MainFrame() {
	BeanFactory beanFactory = new DataBaseDataSource().getDataFactory();
	registrationDAO = (RegistrationDAO) beanFactory
			.getBean("registrationDAO");
	initComponents();
}
 
開發者ID:cyberheartmi9,項目名稱:Mona-Secure-Multi-Owner-Data-Sharing-for-Dynamic-Group-in-the-Cloud,代碼行數:8,代碼來源:MainFrame.java


注:本文中的org.springframework.beans.factory.BeanFactory.getBean方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。