Java 类org.springframework.beans.factory.BeanFactory 实例源码

项目:zipkin-sparkstreaming    文件:ZipkinStorageConsumerAutoConfiguration.java   
@ConditionalOnBean(StorageComponent.class)
@Bean StorageConsumer storageConsumer(
    StorageComponent component,
    @Value("${zipkin.sparkstreaming.consumer.storage.fail-fast:true}") boolean failFast,
    BeanFactory bf
) throws IOException {
  if (failFast) checkStorageOk(component);
  Properties properties = extractZipkinProperties(bf.getBean(ConfigurableEnvironment.class));
  if (component instanceof V2StorageComponent) {
    zipkin2.storage.StorageComponent v2Storage = ((V2StorageComponent) component).delegate();
    if (v2Storage instanceof ElasticsearchHttpStorage) {
      return new ElasticsearchStorageConsumer(properties);
    } else if (v2Storage instanceof zipkin2.storage.cassandra.CassandraStorage) {
      return new Cassandra3StorageConsumer(properties);
    } else {
      throw new UnsupportedOperationException(v2Storage + " not yet supported");
    }
  } else if (component instanceof CassandraStorage) {
    return new CassandraStorageConsumer(properties);
  } else if (component instanceof MySQLStorage) {
    return new MySQLStorageConsumer(properties);
  } else {
    throw new UnsupportedOperationException(component + " not yet supported");
  }
}
项目:parabuild-ci    文件:SpringCreator.java   
/**
 * @return A found BeanFactory configuration
 */
private BeanFactory getBeanFactory()
{
    // If someone has set a resource name then we need to load that.
    if (configLocation != null && configLocation.length > 0)
    {
        log.info("Spring BeanFactory via ClassPathXmlApplicationContext using " + configLocation.length + "configLocations.");
        return new ClassPathXmlApplicationContext(configLocation);
    }

    ServletContext srvCtx = WebContextFactory.get().getServletContext();
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();

    if (request != null)
    {
        return RequestContextUtils.getWebApplicationContext(request, srvCtx);
    }
    else
    {
        return WebApplicationContextUtils.getWebApplicationContext(srvCtx);
    }
}
项目:lams    文件:SimpleInstantiationStrategy.java   
@Override
public Object instantiate(RootBeanDefinition beanDefinition, String beanName, BeanFactory owner,
        final Constructor<?> ctor, Object[] args) {

    if (beanDefinition.getMethodOverrides().isEmpty()) {
        if (System.getSecurityManager() != null) {
            // use own privileged to change accessibility (when security is on)
            AccessController.doPrivileged(new PrivilegedAction<Object>() {
                @Override
                public Object run() {
                    ReflectionUtils.makeAccessible(ctor);
                    return null;
                }
            });
        }
        return BeanUtils.instantiateClass(ctor, args);
    }
    else {
        return instantiateWithMethodInjection(beanDefinition, beanName, owner, ctor, args);
    }
}
项目:lams    文件:AbstractAutowireCapableBeanFactory.java   
/**
 * Instantiate the given bean using its default constructor.
 * @param beanName the name of the bean
 * @param mbd the bean definition for the bean
 * @return BeanWrapper for the new instance
 */
protected BeanWrapper instantiateBean(final String beanName, final RootBeanDefinition mbd) {
    try {
        Object beanInstance;
        final BeanFactory parent = this;
        if (System.getSecurityManager() != null) {
            beanInstance = AccessController.doPrivileged(new PrivilegedAction<Object>() {
                @Override
                public Object run() {
                    return getInstantiationStrategy().instantiate(mbd, beanName, parent);
                }
            }, getAccessControlContext());
        }
        else {
            beanInstance = getInstantiationStrategy().instantiate(mbd, beanName, parent);
        }
        BeanWrapper bw = new BeanWrapperImpl(beanInstance);
        initBeanWrapper(bw);
        return bw;
    }
    catch (Throwable ex) {
        throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Instantiation of bean failed", ex);
    }
}
项目:bucket4j-spring-boot-starter    文件:Bucket4JBaseConfiguration.java   
/**
 * Creates the key filter lambda which is responsible to decide how the rate limit will be performed. The key
 * is the unique identifier like an IP address or a username.
 * 
 * @param url is used to generated a unique cache key
 * @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
 * @param expressionParser is used to evaluate the expression if the filter key type is EXPRESSION.
 * @param beanFactory used to get full access to all java beans in the SpEl
 * @return should not been null. If no filter key type is matching a plain 1 is returned so that all requests uses the same key.
 */
public KeyFilter getKeyFilter(String url, RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {

    switch(rateLimit.getFilterKeyType()) {
    case IP:
        return (request) -> url + "-" + request.getRemoteAddr();
    case EXPRESSION:
        String expression = rateLimit.getExpression();
        if(StringUtils.isEmpty(expression)) {
            throw new MissingKeyFilterExpressionException();
        }
        StandardEvaluationContext context = new StandardEvaluationContext();
        context.setBeanResolver(new BeanFactoryResolver(beanFactory));
        return  (request) -> {
            //TODO performance problem - how can the request object reused in the expression without setting it as a rootObject
            Expression expr = expressionParser.parseExpression(rateLimit.getExpression()); 
            final String value = expr.getValue(context, request, String.class);
            return url + "-" + value;
        };

    }
    return (request) -> url + "-" + "1";
}
项目:lams    文件:AbstractAutowireCapableBeanFactory.java   
@Override
public Object autowire(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException {
    // Use non-singleton bean definition, to avoid registering bean as dependent bean.
    final RootBeanDefinition bd = new RootBeanDefinition(beanClass, autowireMode, dependencyCheck);
    bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    if (bd.getResolvedAutowireMode() == AUTOWIRE_CONSTRUCTOR) {
        return autowireConstructor(beanClass.getName(), bd, null, null).getWrappedInstance();
    }
    else {
        Object bean;
        final BeanFactory parent = this;
        if (System.getSecurityManager() != null) {
            bean = AccessController.doPrivileged(new PrivilegedAction<Object>() {
                @Override
                public Object run() {
                    return getInstantiationStrategy().instantiate(bd, null, parent);
                }
            }, getAccessControlContext());
        }
        else {
            bean = getInstantiationStrategy().instantiate(bd, null, parent);
        }
        populateBean(beanClass.getName(), bd, new BeanWrapperImpl(bean));
        return bean;
    }
}
项目:parabuild-ci    文件:DwrNamespaceHandler.java   
private BeanDefinition findParentDefinition(String parentName, BeanDefinitionRegistry registry)
{   
    if (registry != null) 
    {
        if (registry.containsBeanDefinition(parentName)) 
        {
            return registry.getBeanDefinition(parentName);
        } 
        else if (registry instanceof HierarchicalBeanFactory) 
        {
            // Try to get parent definition from the parent BeanFactory. This could return null
            BeanFactory parentBeanFactory = ((HierarchicalBeanFactory)registry).getParentBeanFactory();
            return findParentDefinition(parentName, (BeanDefinitionRegistry)parentBeanFactory);
        } 
    }

    // we've exhausted all possibilities        
    return null;
}
项目:lams    文件:DeprecatedBeanWarner.java   
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    if (isLogEnabled()) {
        String[] beanNames = beanFactory.getBeanDefinitionNames();
        for (String beanName : beanNames) {
            String nameToLookup = beanName;
            if (beanFactory.isFactoryBean(beanName)) {
                nameToLookup = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
            }
            Class<?> beanType = ClassUtils.getUserClass(beanFactory.getType(nameToLookup));
            if (beanType != null && beanType.isAnnotationPresent(Deprecated.class)) {
                BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
                logDeprecatedBean(beanName, beanType, beanDefinition);
            }
        }
    }
}
项目:gemini.blueprint    文件:ClassUtilsTest.java   
public void testAppContextClassHierarchy() {
    Class<?>[] clazz =
            ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class, ClassUtils.ClassSet.ALL_CLASSES);

       //Closeable.class,
    Class<?>[] expected =
            new Class<?>[] { OsgiBundleXmlApplicationContext.class,
                    AbstractDelegatedExecutionApplicationContext.class, AbstractOsgiBundleApplicationContext.class,
                    AbstractRefreshableApplicationContext.class, AbstractApplicationContext.class,
                    DefaultResourceLoader.class, ResourceLoader.class,
                    AutoCloseable.class,
                    DelegatedExecutionOsgiBundleApplicationContext.class,
                    ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class,
                    ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
                    HierarchicalBeanFactory.class, ApplicationEventPublisher.class, ResourcePatternResolver.class,
                    MessageSource.class, BeanFactory.class, DisposableBean.class };

    assertTrue(compareArrays(expected, clazz));
}
项目:lams    文件:AspectJExpressionPointcut.java   
private FuzzyBoolean contextMatch(Class<?> targetType) {
    String advisedBeanName = getCurrentProxiedBeanName();
    if (advisedBeanName == null) {  // no proxy creation in progress
        // abstain; can't return YES, since that will make pointcut with negation fail
        return FuzzyBoolean.MAYBE;
    }
    if (BeanFactoryUtils.isGeneratedBeanName(advisedBeanName)) {
        return FuzzyBoolean.NO;
    }
    if (targetType != null) {
        boolean isFactory = FactoryBean.class.isAssignableFrom(targetType);
        return FuzzyBoolean.fromBoolean(
                matchesBeanName(isFactory ? BeanFactory.FACTORY_BEAN_PREFIX + advisedBeanName : advisedBeanName));
    }
    else {
        return FuzzyBoolean.fromBoolean(matchesBeanName(advisedBeanName) ||
                matchesBeanName(BeanFactory.FACTORY_BEAN_PREFIX + advisedBeanName));
    }
}
项目:lams    文件:HandlerMethod.java   
/**
 * Create an instance from a bean name, a method, and a {@code BeanFactory}.
 * The method {@link #createWithResolvedBean()} may be used later to
 * re-create the {@code HandlerMethod} with an initialized the bean.
 */
public HandlerMethod(String beanName, BeanFactory beanFactory, Method method) {
    Assert.hasText(beanName, "Bean name is required");
    Assert.notNull(beanFactory, "BeanFactory is required");
    Assert.notNull(method, "Method is required");
    Assert.isTrue(beanFactory.containsBean(beanName),
            "BeanFactory [" + beanFactory + "] does not contain bean [" + beanName + "]");
    this.bean = beanName;
    this.beanFactory = beanFactory;
    this.method = method;
    this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
    this.parameters = initMethodParameters();
}
项目:Mona-Secure-Multi-Owner-Data-Sharing-for-Dynamic-Group-in-the-Cloud    文件:GroupMemberchange.java   
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 {

    }

}
项目:lams    文件:ConfigurationClassParser.java   
/**
 * Invoke {@link ResourceLoaderAware}, {@link BeanClassLoaderAware} and
 * {@link BeanFactoryAware} contracts if implemented by the given {@code bean}.
 */
private void invokeAwareMethods(Object importStrategyBean) {
    if (importStrategyBean instanceof Aware) {
        if (importStrategyBean instanceof EnvironmentAware) {
            ((EnvironmentAware) importStrategyBean).setEnvironment(this.environment);
        }
        if (importStrategyBean instanceof ResourceLoaderAware) {
            ((ResourceLoaderAware) importStrategyBean).setResourceLoader(this.resourceLoader);
        }
        if (importStrategyBean instanceof BeanClassLoaderAware) {
            ClassLoader classLoader = (this.registry instanceof ConfigurableBeanFactory ?
                    ((ConfigurableBeanFactory) this.registry).getBeanClassLoader() :
                    this.resourceLoader.getClassLoader());
            ((BeanClassLoaderAware) importStrategyBean).setBeanClassLoader(classLoader);
        }
        if (importStrategyBean instanceof BeanFactoryAware && this.registry instanceof BeanFactory) {
            ((BeanFactoryAware) importStrategyBean).setBeanFactory((BeanFactory) this.registry);
        }
    }
}
项目:lams    文件:AbstractBeanFactoryBasedTargetSource.java   
/**
 * Set the owning BeanFactory. We need to save a reference so that we can
 * use the {@code getBean} method on every invocation.
 */
@Override
public void setBeanFactory(BeanFactory beanFactory) {
    if (this.targetBeanName == null) {
        throw new IllegalStateException("Property'targetBeanName' is required");
    }
    this.beanFactory = beanFactory;
}
项目:mirrorgate    文件:EventScheduler.java   
@Autowired
public EventScheduler(EventService eventService,
    ConnectionHandler handler, BeanFactory beanFactory){

    this.eventService = eventService;
    this.handler = handler;
    this.beanFactory = beanFactory;
}
项目:alfresco-repository    文件:FullTextSearchIndexerImpl.java   
public void setBeanFactory(BeanFactory beanFactory) throws BeansException
{
    ListableBeanFactory listableBeanFactory = (ListableBeanFactory)beanFactory;

    // Find bean implementaing SupportsBackgroundIndexing and register
    for(Object bgindexable : listableBeanFactory.getBeansOfType(SupportsBackgroundIndexing.class).values())
    {
        if(bgindexable instanceof SupportsBackgroundIndexing)
        {
            ((SupportsBackgroundIndexing)bgindexable).setFullTextSearchIndexer(this);
        }
    }

}
项目:lams    文件:DefaultListableBeanFactory.java   
/**
 * Return whether the bean definition for the given bean name has been
 * marked as a primary bean.
 * @param beanName the name of the bean
 * @param beanInstance the corresponding bean instance
 * @return whether the given bean qualifies as primary
 */
protected boolean isPrimary(String beanName, Object beanInstance) {
    if (containsBeanDefinition(beanName)) {
        return getMergedLocalBeanDefinition(beanName).isPrimary();
    }
    BeanFactory parentFactory = getParentBeanFactory();
    return (parentFactory instanceof DefaultListableBeanFactory &&
            ((DefaultListableBeanFactory) parentFactory).isPrimary(beanName, beanInstance));
}
项目:alfresco-repository    文件:DynamicSolrStoreMappingWrapperFactory.java   
/**
 * @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);
}
项目:parabuild-ci    文件:CloseableBeanFactoryProvider.java   
public synchronized BeanFactory get() {
    if (beanFactory == null)
    {
        beanFactory = loader.loadBeanFactory();
    }
    return beanFactory;
}
项目:bucket4j-spring-boot-starter    文件:Bucket4JBaseConfiguration.java   
/**
 * Creates the lambda for the skip condition which will be evaluated on each request
 * 
 * @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
 * @param expressionParser is used to evaluate the skip expression
 * @param beanFactory used to get full access to all java beans in the SpEl
 * @return the lamdba condition which will be evaluated lazy - null if there is no condition available.
 */
public Condition skipCondition(RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setBeanResolver(new BeanFactoryResolver(beanFactory));

    if(rateLimit.getSkipCondition() != null) {
        return  (request) -> {
            Expression expr = expressionParser.parseExpression(rateLimit.getSkipCondition()); 
            Boolean value = expr.getValue(context, request, Boolean.class);
            return value;
        };
    }
    return null;
}
项目:java-jms    文件:TracingJmsConfiguration.java   
private ConnectionFactory createProxy(final BeanFactory beanFactory) {
  return (ConnectionFactory) ProxyFactory.getProxy(new AbstractLazyCreationTargetSource() {
    @Override
    public synchronized Class<?> getTargetClass() {
      return ConnectionFactory.class;
    }

    @Override
    protected Object createObject() throws Exception {
      return beanFactory.getBean(ConnectionFactory.class);
    }
  });
}
项目:lams    文件:EntityManagerFactoryAccessor.java   
/**
 * Retrieves an EntityManagerFactory by persistence unit name, if none set explicitly.
 * Falls back to a default EntityManagerFactory bean if no persistence unit specified.
 * @see #setPersistenceUnitName
 */
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
    if (getEntityManagerFactory() == null) {
        if (!(beanFactory instanceof ListableBeanFactory)) {
            throw new IllegalStateException("Cannot retrieve EntityManagerFactory by persistence unit name " +
                    "in a non-listable BeanFactory: " + beanFactory);
        }
        ListableBeanFactory lbf = (ListableBeanFactory) beanFactory;
        setEntityManagerFactory(EntityManagerFactoryUtils.findEntityManagerFactory(lbf, getPersistenceUnitName()));
    }
}
项目:lams    文件:SpringBeanELResolver.java   
@Override
public Object getValue(ELContext elContext, Object base, Object property) throws ELException {
    if (base == null) {
        String beanName = property.toString();
        BeanFactory bf = getBeanFactory(elContext);
        if (bf.containsBean(beanName)) {
            if (logger.isTraceEnabled()) {
                logger.trace("Successfully resolved variable '" + beanName + "' in Spring BeanFactory");
            }
            elContext.setPropertyResolved(true);
            return bf.getBean(beanName);
        }
    }
    return null;
}
项目:lams    文件:JpaTransactionManager.java   
/**
 * Retrieves an EntityManagerFactory by persistence unit name, if none set explicitly.
 * Falls back to a default EntityManagerFactory bean if no persistence unit specified.
 * @see #setPersistenceUnitName
 */
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
    if (getEntityManagerFactory() == null) {
        if (!(beanFactory instanceof ListableBeanFactory)) {
            throw new IllegalStateException("Cannot retrieve EntityManagerFactory by persistence unit name " +
                    "in a non-listable BeanFactory: " + beanFactory);
        }
        ListableBeanFactory lbf = (ListableBeanFactory) beanFactory;
        setEntityManagerFactory(EntityManagerFactoryUtils.findEntityManagerFactory(lbf, getPersistenceUnitName()));
    }
}
项目:gemini.blueprint    文件:SecurityUtils.java   
public static AccessControlContext getAccFrom(BeanFactory beanFactory) {
    AccessControlContext acc = null;
    if (beanFactory != null) {
        if (beanFactory instanceof ConfigurableBeanFactory) {
            return ((ConfigurableBeanFactory) beanFactory).getAccessControlContext();
        }
    }
    return acc;
}
项目:spring-zeebe    文件:ZeebeExpressionResolver.java   
@Override
public void setBeanFactory(final BeanFactory beanFactory) throws BeansException
{
    this.beanFactory = beanFactory;
    if (beanFactory instanceof ConfigurableListableBeanFactory)
    {
        this.resolver = ((ConfigurableListableBeanFactory) beanFactory).getBeanExpressionResolver();
        this.expressionContext = new BeanExpressionContext((ConfigurableListableBeanFactory) beanFactory, null);
    }
}
项目:lams    文件:AbstractBeanFactory.java   
@Override
public String[] getAliases(String name) {
    String beanName = transformedBeanName(name);
    List<String> aliases = new ArrayList<String>();
    boolean factoryPrefix = name.startsWith(FACTORY_BEAN_PREFIX);
    String fullBeanName = beanName;
    if (factoryPrefix) {
        fullBeanName = FACTORY_BEAN_PREFIX + beanName;
    }
    if (!fullBeanName.equals(name)) {
        aliases.add(fullBeanName);
    }
    String[] retrievedAliases = super.getAliases(beanName);
    for (String retrievedAlias : retrievedAliases) {
        String alias = (factoryPrefix ? FACTORY_BEAN_PREFIX : "") + retrievedAlias;
        if (!alias.equals(name)) {
            aliases.add(alias);
        }
    }
    if (!containsSingleton(beanName) && !containsBeanDefinition(beanName)) {
        BeanFactory parentBeanFactory = getParentBeanFactory();
        if (parentBeanFactory != null) {
            aliases.addAll(Arrays.asList(parentBeanFactory.getAliases(fullBeanName)));
        }
    }
    return StringUtils.toStringArray(aliases);
}
项目:lams    文件:AbstractAdvisorAutoProxyCreator.java   
@Override
public void setBeanFactory(BeanFactory beanFactory) {
    super.setBeanFactory(beanFactory);
    if (!(beanFactory instanceof ConfigurableListableBeanFactory)) {
        throw new IllegalStateException("Cannot use AdvisorAutoProxyCreator without a ConfigurableListableBeanFactory");
    }
    initBeanFactory((ConfigurableListableBeanFactory) beanFactory);
}
项目:lams    文件:SpringBeanAutowiringInterceptor.java   
/**
 * Determine the BeanFactory for autowiring the given target bean.
 * @param target the target bean to autowire
 * @return the BeanFactory to use (never {@code null})
 * @see #getBeanFactoryReference
 */
protected BeanFactory getBeanFactory(Object target) {
    BeanFactory factory = getBeanFactoryReference(target).getFactory();
    if (factory instanceof ApplicationContext) {
        factory = ((ApplicationContext) factory).getAutowireCapableBeanFactory();
    }
    return factory;
}
项目:lams    文件:ScopedProxyFactoryBean.java   
@Override
public void setBeanFactory(BeanFactory beanFactory) {
    if (!(beanFactory instanceof ConfigurableBeanFactory)) {
        throw new IllegalStateException("Not running in a ConfigurableBeanFactory: " + beanFactory);
    }
    ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory;

    this.scopedTargetSource.setBeanFactory(beanFactory);

    ProxyFactory pf = new ProxyFactory();
    pf.copyFrom(this);
    pf.setTargetSource(this.scopedTargetSource);

    Class<?> beanType = beanFactory.getType(this.targetBeanName);
    if (beanType == null) {
        throw new IllegalStateException("Cannot create scoped proxy for bean '" + this.targetBeanName +
                "': Target type could not be determined at the time of proxy creation.");
    }
    if (!isProxyTargetClass() || beanType.isInterface() || Modifier.isPrivate(beanType.getModifiers())) {
        pf.setInterfaces(ClassUtils.getAllInterfacesForClass(beanType, cbf.getBeanClassLoader()));
    }

    // Add an introduction that implements only the methods on ScopedObject.
    ScopedObject scopedObject = new DefaultScopedObject(cbf, this.scopedTargetSource.getTargetBeanName());
    pf.addAdvice(new DelegatingIntroductionInterceptor(scopedObject));

    // Add the AopInfrastructureBean marker to indicate that the scoped proxy
    // itself is not subject to auto-proxying! Only its target bean is.
    pf.addInterface(AopInfrastructureBean.class);

    this.proxy = pf.getProxy(cbf.getBeanClassLoader());
}
项目:lams    文件:SimpleInstantiationStrategy.java   
/**
 * Subclasses can override this method, which is implemented to throw
 * UnsupportedOperationException, if they can instantiate an object with
 * the Method Injection specified in the given RootBeanDefinition.
 * Instantiation should use the given constructor and parameters.
 */
protected Object instantiateWithMethodInjection(RootBeanDefinition beanDefinition,
        String beanName, BeanFactory owner, Constructor<?> ctor, Object[] args) {

    throw new UnsupportedOperationException(
            "Method Injection not supported in SimpleInstantiationStrategy");
}
项目:lams    文件:AbstractApplicationEventMulticaster.java   
private BeanFactory getBeanFactory() {
    if (this.beanFactory == null) {
        throw new IllegalStateException("ApplicationEventMulticaster cannot retrieve listener beans " +
                "because it is not associated with a BeanFactory");
    }
    return this.beanFactory;
}
项目:lams    文件:DefaultLifecycleProcessor.java   
@Override
public void setBeanFactory(BeanFactory beanFactory) {
    Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory);
    this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
}
项目:lams    文件:SimpleBeanFactoryAwareAspectInstanceFactory.java   
@Override
public void setBeanFactory(BeanFactory beanFactory) {
    this.beanFactory = beanFactory;
    if (!StringUtils.hasText(this.aspectBeanName)) {
        throw new IllegalArgumentException("'aspectBeanName' is required");
    }
}
项目:lams    文件:CommonAnnotationBeanPostProcessor.java   
/**
 * 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;
}
项目:lams    文件:MBeanExporter.java   
/**
 * This callback is only required for resolution of bean names in the
 * {@link #setBeans(java.util.Map) "beans"} {@link Map} and for
 * autodetection of MBeans (in the latter case, a
 * {@code ListableBeanFactory} is required).
 * @see #setBeans
 * @see #setAutodetect
 */
@Override
public void setBeanFactory(BeanFactory beanFactory) {
    if (beanFactory instanceof ListableBeanFactory) {
        this.beanFactory = (ListableBeanFactory) beanFactory;
    }
    else {
        logger.info("MBeanExporter not running in a ListableBeanFactory: autodetection of MBeans not available.");
    }
}
项目:Learning-Spring-5.0    文件:TestBeanFactory.java   
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");

}
项目:lams    文件:PersistenceExceptionTranslationPostProcessor.java   
@Override
public void setBeanFactory(BeanFactory beanFactory) {
    if (!(beanFactory instanceof ListableBeanFactory)) {
        throw new IllegalArgumentException(
                "Cannot use PersistenceExceptionTranslator autodetection without ListableBeanFactory");
    }
    this.advisor = new PersistenceExceptionTranslationAdvisor(
            (ListableBeanFactory) beanFactory, this.repositoryAnnotationType);
}
项目:lams    文件:PersistenceExceptionTranslationInterceptor.java   
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
    if (this.persistenceExceptionTranslator == null) {
        // No explicit exception translator specified - perform autodetection.
        if (!(beanFactory instanceof ListableBeanFactory)) {
            throw new IllegalArgumentException(
                    "Cannot use PersistenceExceptionTranslator autodetection without ListableBeanFactory");
        }
        this.beanFactory = (ListableBeanFactory) beanFactory;
    }
}
项目:marshalsec    文件:SpringUtil.java   
public static BeanFactory makeJNDITrigger ( String jndiUrl ) throws Exception {
    SimpleJndiBeanFactory bf = new SimpleJndiBeanFactory();
    bf.setShareableResources(jndiUrl);
    Reflections.setFieldValue(bf, "logger", new NoOpLog());
    Reflections.setFieldValue(bf.getJndiTemplate(), "logger", new NoOpLog());
    return bf;
}