本文整理匯總了Java中org.springframework.beans.factory.config.BeanDefinition.getBeanClassName方法的典型用法代碼示例。如果您正苦於以下問題:Java BeanDefinition.getBeanClassName方法的具體用法?Java BeanDefinition.getBeanClassName怎麽用?Java BeanDefinition.getBeanClassName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.beans.factory.config.BeanDefinition
的用法示例。
在下文中一共展示了BeanDefinition.getBeanClassName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setConfigBeanFactoryMethod
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
/**
* 修改配置Bean定義,使用靜態方法{@link ConfigBeanFactory#FACTORY_METHOD}來實例化。
*
* @param registry
* @param beanName
* @param beanDefinition
* @param propertyName
* @param converterType
*/
public static void setConfigBeanFactoryMethod(BeanDefinitionRegistry registry,
String beanName, BeanDefinition beanDefinition,
String propertyName, Class<?> converterType) {
// 注冊ConfigBeanPropertyResolver
registerConfigBeanPropertyResolver(registry);
// 注冊ConfigBeanConversionService
registerConfigBeanConversionService(registry);
String beanClassName = beanDefinition.getBeanClassName();
beanDefinition.setBeanClassName(ConfigBeanFactory.class.getName());
beanDefinition.setFactoryMethodName(ConfigBeanFactory.FACTORY_METHOD);
ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
constructorArgumentValues.addGenericArgumentValue(propertyName, String.class.getName());
constructorArgumentValues.addGenericArgumentValue(beanClassName, Class.class.getName());
constructorArgumentValues.addGenericArgumentValue(converterType);
constructorArgumentValues.addGenericArgumentValue(new RuntimeBeanReference(CONFIG_BEAN_PROPERTY_RESOLVER_BEAN_NAME));
constructorArgumentValues.addGenericArgumentValue(new RuntimeBeanReference(CONFIG_BEAN_CONVERSION_SERVICE_BEAN_NAME));
beanDefinition.getConstructorArgumentValues().addArgumentValues(constructorArgumentValues);
}
示例2: registerFactoryMethodForConfigBean
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
/**
* 為@ConfigBean的bean注冊它的Factory Method,通過靜態Factory Method來創建@ConfigBean實例
*
* @param registry
* @param beanName
* @param beanDefinition
*/
private void registerFactoryMethodForConfigBean(BeanDefinitionRegistry registry, String beanName, BeanDefinition beanDefinition) {
String beanClassName = beanDefinition.getBeanClassName();
if (beanClassName == null) { // 通過注解@Bean聲明的bean,beanClassName=null
return;
}
Class<?> beanClass = ClassUtils.resolveClassName(beanClassName, beanFactory.getBeanClassLoader());
ConfigBean config = AnnotationUtils.findAnnotation(beanClass, ConfigBean.class);
if (config == null) {
return;
}
// 為配置bean設置factory method
String propertyName = config.value();
ConfigBeanConfigUtils.setConfigBeanFactoryMethod(registry,
beanName, beanDefinition, propertyName, config.converter());
}
示例3: buildDefaultBeanName
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
@Override
protected String buildDefaultBeanName(BeanDefinition definition) {
if(this.packageDepth < 1){
return super.buildDefaultBeanName(definition);
}
String fullName = definition.getBeanClassName(); //e.g.: com.mobanker.tkj.api.action.UserAction
char delimiter = dotReplacement > 0 ? dotReplacement : DEFAULT_DOT_REPLACEMENT;
String[] names = fullName.split("\\.");
StringBuilder beanName = new StringBuilder("");
//add package name
if(names.length > 1){
for(int i = 0; i < this.packageDepth; i++){
String name = names[names.length - 2 - i];
beanName.insert(0, delimiter);
beanName.insert(0, name);
}
}
//add Class name
beanName.append(names[names.length - 1]);
return beanName.toString();
}
示例4: buildDefaultBeanName
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
@Override
protected String buildDefaultBeanName(BeanDefinition definition) {
if(this.packageDepth < 1){
return super.buildDefaultBeanName(definition);
}
String fullName = definition.getBeanClassName(); //e.g.: com.tasfe.tkj.api.action.UserAction
char delimiter = dotReplacement > 0 ? dotReplacement : DEFAULT_DOT_REPLACEMENT;
String[] names = fullName.split("\\.");
StringBuilder beanName = new StringBuilder("");
//add package name
if(names.length > 1){
for(int i = 0; i < this.packageDepth; i++){
String name = names[names.length - 2 - i];
beanName.insert(0, delimiter);
beanName.insert(0, name);
}
}
//add Class name
beanName.append(names[names.length - 1]);
return beanName.toString();
}
示例5: buildDefaultBeanName
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
@Override
protected String buildDefaultBeanName(BeanDefinition definition) {
if (this.packageDepth < 1) {
return super.buildDefaultBeanName(definition);
}
String fullName = definition.getBeanClassName(); //e.g.: com.tasfe.tkj.api.action.UserAction
char delimiter = dotReplacement > 0 ? dotReplacement : DEFAULT_DOT_REPLACEMENT;
String[] names = fullName.split("\\.");
StringBuilder beanName = new StringBuilder("");
//add package name
if (names.length > 1) {
for (int i = 0; i < this.packageDepth; i++) {
String name = names[names.length - 2 - i];
beanName.insert(0, delimiter);
beanName.insert(0, name);
}
}
//add Class name
beanName.append(names[names.length - 1]);
return beanName.toString();
}
示例6: parse
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
public void parse(Set<BeanDefinitionHolder> configCandidates) {
for (BeanDefinitionHolder holder : configCandidates) {
BeanDefinition bd = holder.getBeanDefinition();
try {
if (bd instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) bd).hasBeanClass()) {
parse(((AbstractBeanDefinition) bd).getBeanClass(), holder.getBeanName());
}
else {
parse(bd.getBeanClassName(), holder.getBeanName());
}
}
catch (IOException ex) {
throw new BeanDefinitionStoreException("Failed to load bean class: " + bd.getBeanClassName(), ex);
}
}
processDeferredImportSelectors();
}
示例7: checkCandidate
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
/**
* Check the given candidate's bean name, determining whether the corresponding
* bean definition needs to be registered or conflicts with an existing definition.
* @param beanName the suggested name for the bean
* @param beanDefinition the corresponding bean definition
* @return {@code true} if the bean can be registered as-is;
* {@code false} if it should be skipped because there is an
* existing, compatible bean definition for the specified name
* @throws ConflictingBeanDefinitionException if an existing, incompatible
* bean definition has been found for the specified name
*/
protected boolean checkCandidate(String beanName, BeanDefinition beanDefinition) throws IllegalStateException {
if (!this.registry.containsBeanDefinition(beanName)) {
return true;
}
BeanDefinition existingDef = this.registry.getBeanDefinition(beanName);
BeanDefinition originatingDef = existingDef.getOriginatingBeanDefinition();
if (originatingDef != null) {
existingDef = originatingDef;
}
if (isCompatible(beanDefinition, existingDef)) {
return false;
}
throw new ConflictingBeanDefinitionException("Annotation-specified bean name '" + beanName +
"' for bean class [" + beanDefinition.getBeanClassName() + "] conflicts with existing, " +
"non-compatible bean definition of same name and class [" + existingDef.getBeanClassName() + "]");
}
示例8: getBeanFactoryClassName
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
/**
* Get the Factory class name which corresponds to given bean definition.
* @param definition Bean definition
* @param beanFactory Bean factory
* @return Factory class name, or <code>null</code> if not found
*/
private static String getBeanFactoryClassName(BeanDefinition definition,
ConfigurableListableBeanFactory beanFactory) {
if (definition instanceof AnnotatedBeanDefinition) {
return ((AnnotatedBeanDefinition) definition).getMetadata().getClassName();
} else {
if (definition.getFactoryBeanName() != null) {
BeanDefinition fd = beanFactory.getBeanDefinition(definition.getFactoryBeanName());
if (fd != null) {
return fd.getBeanClassName();
}
} else {
return definition.getBeanClassName();
}
}
return null;
}
示例9: getServiceDependencies
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
public Collection<OsgiServiceDependency> getServiceDependencies(BundleContext bundleContext,
ConfigurableListableBeanFactory beanFactory) throws BeansException, InvalidSyntaxException, BundleException {
Set<OsgiServiceDependency> dependencies = new LinkedHashSet<OsgiServiceDependency>();
String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
for (String definitionName : beanDefinitionNames) {
BeanDefinition definition = beanFactory.getBeanDefinition(definitionName);
String className = definition.getBeanClassName();
// Ignore internal stuff
if (className == null
|| className.equals(OsgiServiceProxyFactoryBean.class.getName())
|| className.equals(OsgiServiceFactoryBean.class.getName())
|| className.equals(OsgiServiceCollectionProxyFactoryBean.class.getName())) {
continue;
}
try {
Class<?> clazz = Class.forName(className, true, beanFactory.getBeanClassLoader());
dependencies.addAll(getClassServiceDependencies(clazz, definitionName, definition));
}
catch (ClassNotFoundException cnfe) {
if (logger.isDebugEnabled())
logger.debug("Could not load class [" + className + "] for ["
+ bundleContext.getBundle().getSymbolicName() + "]");
}
}
if (logger.isDebugEnabled())
logger.debug("Processing annotations for [" + bundleContext.getBundle().getSymbolicName() + "] found "
+ dependencies);
return dependencies;
}
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:33,代碼來源:ServiceReferenceDependencyBeanFactoryPostProcessor.java
示例10: resolveScopeMetadata
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
@Override
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
ScopeMetadata metadata = new ScopeMetadata();
metadata.setScopeName(BeanDefinition.SCOPE_PROTOTYPE);
if (definition instanceof AnnotatedBeanDefinition) {
AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
Set<String> annTypes = annDef.getMetadata().getAnnotationTypes();
String found = null;
for (String annType : annTypes) {
Set<String> metaAnns = annDef.getMetadata().getMetaAnnotationTypes(annType);
if (metaAnns.contains("javax.inject.Scope")) {
if (found != null) {
throw new IllegalStateException("Found ambiguous scope annotations on bean class [" +
definition.getBeanClassName() + "]: " + found + ", " + annType);
}
found = annType;
String scopeName = resolveScopeName(annType);
if (scopeName == null) {
throw new IllegalStateException(
"Unsupported scope annotation - not mapped onto Spring scope name: " + annType);
}
metadata.setScopeName(scopeName);
}
}
}
return metadata;
}
示例11: generateBeanName
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
/**
* Generate a bean name for the given bean definition, unique within the
* given bean factory.
* @param definition the bean definition to generate a bean name for
* @param registry the bean factory that the definition is going to be
* registered with (to check for existing bean names)
* @param isInnerBean whether the given bean definition will be registered
* as inner bean or as top-level bean (allowing for special name generation
* for inner beans versus top-level beans)
* @return the generated bean name
* @throws BeanDefinitionStoreException if no unique name can be generated
* for the given bean definition
*/
public static String generateBeanName(
BeanDefinition definition, BeanDefinitionRegistry registry, boolean isInnerBean)
throws BeanDefinitionStoreException {
String generatedBeanName = definition.getBeanClassName();
if (generatedBeanName == null) {
if (definition.getParentName() != null) {
generatedBeanName = definition.getParentName() + "$child";
}
else if (definition.getFactoryBeanName() != null) {
generatedBeanName = definition.getFactoryBeanName() + "$created";
}
}
if (!StringUtils.hasText(generatedBeanName)) {
throw new BeanDefinitionStoreException("Unnamed bean definition specifies neither " +
"'class' nor 'parent' nor 'factory-bean' - can't generate bean name");
}
String id = generatedBeanName;
if (isInnerBean) {
// Inner bean: generate identity hashcode suffix.
id = generatedBeanName + GENERATED_BEAN_NAME_SEPARATOR + ObjectUtils.getIdentityHexString(definition);
}
else {
// Top-level bean: use plain class name.
// Increase counter until the id is unique.
int counter = -1;
while (counter == -1 || registry.containsBeanDefinition(id)) {
counter++;
id = generatedBeanName + GENERATED_BEAN_NAME_SEPARATOR + counter;
}
}
return id;
}
示例12: postProcessBeanFactory
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException {
// get names of all BeanDefinition
String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
for (String name: beanDefinitionNames) {
// get BeanDefinition by name
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(name);
/* получаем имя класса создавамого бина, чтобы проверить ,
* содержит ли он аннотацию UnsupportedCameraRoll
*/
String className = beanDefinition.getBeanClassName();
try {
// get class by name
Class<?> beanClass = Class.forName(className);
/* пытаемся получить объект аннотации и ее значение,
* если класс не содержит данную аннотацию, то метод вернет null
*/
UnproducableCameraRoll annotation = beanClass.getAnnotation(UnproducableCameraRoll.class);
// проверяем, содержал ли класс эту аннотацию
if (annotation != null) {
// получаем значение указанное в параметрах аннотации(класс пленки, которую необходимо использовать)
Class usingCameraRollName =annotation.usingCameraRollClass();
// меняем класс будущего бина!
beanDefinition.setBeanClassName(usingCameraRollName.getName());
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
示例13: resolveBeanClassname
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
/**
* Try getting the beanClassName from the definition and if that fails try to get it from
* the parent (and even parent BeanFactory if we have to).
*
* @param definition
* @param registry
* @return class name or null if not found
*/
private String resolveBeanClassname(BeanDefinition definition, BeanDefinitionRegistry registry)
{
String beanClassName = definition.getBeanClassName();
if (!StringUtils.hasText(beanClassName))
{
while (definition instanceof ChildBeanDefinition )
{
String parentName = ((ChildBeanDefinition)definition).getParentName();
BeanDefinition parentDefinition = findParentDefinition(parentName, registry);
if (parentDefinition == null)
{
if (log.isDebugEnabled())
{
log.debug("No parent bean named '" + parentName + "' could be found in the " +
"hierarchy of BeanFactorys. Check you've defined a bean called '" + parentName + "'");
}
break;
}
beanClassName = parentDefinition.getBeanClassName();
if (StringUtils.hasText(beanClassName ))
{
// found the class name we were looking for
break;
}
definition = parentDefinition;
}
}
return beanClassName;
}
示例14: generateBeanName
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
@Override
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
return definition.getBeanClassName();
}
示例15: buildDefaultBeanName
import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
@Override
protected String buildDefaultBeanName(BeanDefinition definition) {
return definition.getBeanClassName();
}