本文整理匯總了Java中org.springframework.beans.factory.BeanFactoryAware類的典型用法代碼示例。如果您正苦於以下問題:Java BeanFactoryAware類的具體用法?Java BeanFactoryAware怎麽用?Java BeanFactoryAware使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BeanFactoryAware類屬於org.springframework.beans.factory包,在下文中一共展示了BeanFactoryAware類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: postProcessBeanFactory
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
public void postProcessBeanFactory(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory)
throws BeansException, OsgiException {
Bundle bundle = bundleContext.getBundle();
try {
// Try and load the annotation code using the bundle classloader
Class<?> annotationBppClass = bundle.loadClass(ANNOTATION_BPP_CLASS);
// instantiate the class
final BeanPostProcessor annotationBeanPostProcessor = (BeanPostProcessor) BeanUtils.instantiateClass(annotationBppClass);
// everything went okay so configure the BPP and add it to the BF
((BeanFactoryAware) annotationBeanPostProcessor).setBeanFactory(beanFactory);
((BeanClassLoaderAware) annotationBeanPostProcessor).setBeanClassLoader(beanFactory.getBeanClassLoader());
((BundleContextAware) annotationBeanPostProcessor).setBundleContext(bundleContext);
beanFactory.addBeanPostProcessor(annotationBeanPostProcessor);
}
catch (ClassNotFoundException exception) {
log.info("Spring-DM annotation package could not be loaded from bundle ["
+ OsgiStringUtils.nullSafeNameAndSymName(bundle) + "]; annotation processing disabled...");
if (log.isDebugEnabled())
log.debug("Cannot load annotation injection processor", exception);
}
}
示例2: enforceExporterImporterDependency
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
/**
* Takes care of enforcing the relationship between exporter and importers.
*
* @param beanFactory
*/
private void enforceExporterImporterDependency(ConfigurableListableBeanFactory beanFactory) {
Object instance = null;
instance = AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
// create the service manager
ClassLoader loader = AbstractOsgiBundleApplicationContext.class.getClassLoader();
try {
Class<?> managerClass = loader.loadClass(EXPORTER_IMPORTER_DEPENDENCY_MANAGER);
return BeanUtils.instantiateClass(managerClass);
} catch (ClassNotFoundException cnfe) {
throw new ApplicationContextException("Cannot load class " + EXPORTER_IMPORTER_DEPENDENCY_MANAGER,
cnfe);
}
}
});
// sanity check
Assert.isInstanceOf(BeanFactoryAware.class, instance);
Assert.isInstanceOf(BeanPostProcessor.class, instance);
((BeanFactoryAware) instance).setBeanFactory(beanFactory);
beanFactory.addBeanPostProcessor((BeanPostProcessor) instance);
}
示例3: invokeAwareMethods
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
/**
* 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);
}
}
}
示例4: setAutowireCandidateResolver
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
/**
* Set a custom autowire candidate resolver for this BeanFactory to use
* when deciding whether a bean definition should be considered as a
* candidate for autowiring.
*/
public void setAutowireCandidateResolver(final AutowireCandidateResolver autowireCandidateResolver) {
Assert.notNull(autowireCandidateResolver, "AutowireCandidateResolver must not be null");
if (autowireCandidateResolver instanceof BeanFactoryAware) {
if (System.getSecurityManager() != null) {
final BeanFactory target = this;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(target);
return null;
}
}, getAccessControlContext());
}
else {
((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(this);
}
}
this.autowireCandidateResolver = autowireCandidateResolver;
}
示例5: invokeAwareMethods
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
/**
* Invoke {@link ResourceLoaderAware}, {@link BeanClassLoaderAware} and
* {@link BeanFactoryAware} contracts if implemented by the given {@code filter}.
*/
private void invokeAwareMethods(TypeFilter filter) {
if (filter instanceof Aware) {
if (filter instanceof EnvironmentAware) {
((EnvironmentAware) filter).setEnvironment(this.environment);
}
if (filter instanceof ResourceLoaderAware) {
((ResourceLoaderAware) filter).setResourceLoader(this.resourceLoader);
}
if (filter instanceof BeanClassLoaderAware) {
ClassLoader classLoader = (this.registry instanceof ConfigurableBeanFactory ?
((ConfigurableBeanFactory) this.registry).getBeanClassLoader() :
this.resourceLoader.getClassLoader());
((BeanClassLoaderAware) filter).setBeanClassLoader(classLoader);
}
if (filter instanceof BeanFactoryAware && this.registry instanceof BeanFactory) {
((BeanFactoryAware) filter).setBeanFactory((BeanFactory) this.registry);
}
}
}
示例6: invokeAwareMethods
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
/**
* Invoke {@link EnvironmentAware}, {@link ResourceLoaderAware}, {@link BeanClassLoaderAware}
* and {@link BeanFactoryAware} contracts if implemented by the given {@code registrar}.
*/
private void invokeAwareMethods(ImportBeanDefinitionRegistrar registrar) {
if (registrar instanceof Aware) {
if (registrar instanceof EnvironmentAware) {
((EnvironmentAware) registrar).setEnvironment(this.environment);
}
if (registrar instanceof ResourceLoaderAware) {
((ResourceLoaderAware) registrar).setResourceLoader(this.resourceLoader);
}
if (registrar instanceof BeanClassLoaderAware) {
ClassLoader classLoader = (this.registry instanceof ConfigurableBeanFactory ?
((ConfigurableBeanFactory) this.registry).getBeanClassLoader() :
this.resourceLoader.getClassLoader());
((BeanClassLoaderAware) registrar).setBeanClassLoader(classLoader);
}
if (registrar instanceof BeanFactoryAware && this.registry instanceof BeanFactory) {
((BeanFactoryAware) registrar).setBeanFactory((BeanFactory) this.registry);
}
}
}
示例7: setAutowireCandidateResolver
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
/**
* Set a custom autowire candidate resolver for this BeanFactory to use
* when deciding whether a bean definition should be considered as a
* candidate for autowiring.
*/
public void setAutowireCandidateResolver(final AutowireCandidateResolver autowireCandidateResolver) {
Assert.notNull(autowireCandidateResolver, "AutowireCandidateResolver must not be null");
if (autowireCandidateResolver instanceof BeanFactoryAware) {
if (System.getSecurityManager() != null) {
final BeanFactory target = this;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(target);
return null;
}
}, getAccessControlContext());
}
else {
((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(this);
}
}
this.autowireCandidateResolver = autowireCandidateResolver;
}
示例8: setAutowireCandidateResolver
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
/**
* Set a custom autowire candidate resolver for this BeanFactory to use
* when deciding whether a bean definition should be considered as a
* candidate for autowiring.
*/
public void setAutowireCandidateResolver(final AutowireCandidateResolver autowireCandidateResolver) {
Assert.notNull(autowireCandidateResolver, "AutowireCandidateResolver must not be null");
if (autowireCandidateResolver instanceof BeanFactoryAware) {
if (System.getSecurityManager() != null) {
final BeanFactory target = this;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(target);
return null;
}
}, getAccessControlContext());
}
else {
((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(this);
}
}
this.autowireCandidateResolver = autowireCandidateResolver;
}
示例9: postProcessBeanFactory
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
public void postProcessBeanFactory(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory)
throws BeansException, OsgiException {
Bundle bundle = bundleContext.getBundle();
try {
// Try and load the annotation code using the bundle classloader
Class annotationBppClass = bundle.loadClass(ANNOTATION_BPP_CLASS);
// instantiate the class
final BeanPostProcessor annotationBeanPostProcessor = (BeanPostProcessor) BeanUtils.instantiateClass(annotationBppClass);
// everything went okay so configure the BPP and add it to the BF
((BeanFactoryAware) annotationBeanPostProcessor).setBeanFactory(beanFactory);
((BeanClassLoaderAware) annotationBeanPostProcessor).setBeanClassLoader(beanFactory.getBeanClassLoader());
((BundleContextAware) annotationBeanPostProcessor).setBundleContext(bundleContext);
beanFactory.addBeanPostProcessor(annotationBeanPostProcessor);
}
catch (ClassNotFoundException exception) {
log.info("Spring-DM annotation package could not be loaded from bundle ["
+ OsgiStringUtils.nullSafeNameAndSymName(bundle) + "]; annotation processing disabled...");
if (log.isDebugEnabled())
log.debug("Cannot load annotation injection processor", exception);
}
}
示例10: enforceExporterImporterDependency
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
/**
* Takes care of enforcing the relationship between exporter and importers.
*
* @param beanFactory
*/
private void enforceExporterImporterDependency(ConfigurableListableBeanFactory beanFactory) {
Object instance = null;
instance = AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
// create the service manager
ClassLoader loader = AbstractOsgiBundleApplicationContext.class.getClassLoader();
try {
Class managerClass = loader.loadClass(EXPORTER_IMPORTER_DEPENDENCY_MANAGER);
return BeanUtils.instantiateClass(managerClass);
}
catch (ClassNotFoundException cnfe) {
throw new ApplicationContextException("Cannot load class " + EXPORTER_IMPORTER_DEPENDENCY_MANAGER,
cnfe);
}
}
});
// sanity check
Assert.isInstanceOf(BeanFactoryAware.class, instance);
Assert.isInstanceOf(BeanPostProcessor.class, instance);
((BeanFactoryAware) instance).setBeanFactory(beanFactory);
beanFactory.addBeanPostProcessor((BeanPostProcessor) instance);
}
示例11: setBeanFactory
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
/**
* Set the {@code BeanFactory} to be used when looking up executors by qualifier.
*/
@Override
public void setBeanFactory(BeanFactory beanFactory) {
if (this.advice instanceof BeanFactoryAware) {
((BeanFactoryAware) this.advice).setBeanFactory(beanFactory);
}
}
示例12: intercept
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
Field field = obj.getClass().getDeclaredField(BEAN_FACTORY_FIELD);
Assert.state(field != null, "Unable to find generated BeanFactory field");
field.set(obj, args[0]);
// Does the actual (non-CGLIB) superclass actually implement BeanFactoryAware?
// If so, call its setBeanFactory() method. If not, just exit.
if (BeanFactoryAware.class.isAssignableFrom(obj.getClass().getSuperclass())) {
return proxy.invokeSuper(obj, args);
}
return null;
}
示例13: isMatch
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
@Override
public boolean isMatch(Method candidateMethod) {
return candidateMethod.getName().equals("setBeanFactory") &&
candidateMethod.getParameterTypes().length == 1 &&
candidateMethod.getParameterTypes()[0].equals(BeanFactory.class) &&
BeanFactoryAware.class.isAssignableFrom(candidateMethod.getDeclaringClass());
}
示例14: AbstractAutowireCapableBeanFactory
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
/**
* Create a new AbstractAutowireCapableBeanFactory.
*/
public AbstractAutowireCapableBeanFactory() {
super();
ignoreDependencyInterface(BeanNameAware.class);
ignoreDependencyInterface(BeanFactoryAware.class);
ignoreDependencyInterface(BeanClassLoaderAware.class);
}
示例15: invokeAwareMethods
import org.springframework.beans.factory.BeanFactoryAware; //導入依賴的package包/類
private void invokeAwareMethods(final String beanName, final Object bean) {
if (bean instanceof Aware) {
if (bean instanceof BeanNameAware) {
((BeanNameAware) bean).setBeanName(beanName);
}
if (bean instanceof BeanClassLoaderAware) {
((BeanClassLoaderAware) bean).setBeanClassLoader(getBeanClassLoader());
}
if (bean instanceof BeanFactoryAware) {
((BeanFactoryAware) bean).setBeanFactory(AbstractAutowireCapableBeanFactory.this);
}
}
}