本文整理汇总了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);
}
}
示例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.)");
}
}
示例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");
}
}
}
}
示例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);
}
示例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;
}
示例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;
}
}
示例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);
}
示例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);
}
}
示例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());
}
}
示例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);
}
示例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);
}
示例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