Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xml/注解方式定义的消费服务bean如何配合@Conditional相关注解 #779

Open
lduffy69 opened this issue Feb 8, 2021 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@lduffy69
Copy link

lduffy69 commented Feb 8, 2021

如题,在@ConditionalOnBean/@ConditionalOnMissingBean下:

@ConditionalOnMissingBean(value = UserService.class, parameterizedContainer = {ReferenceBean.class})

失效,在Condition相关注解扫描beanDefination时,获取的RootBD是Reference<?>,导致不能匹配,是否在registerBD时,未考虑泛型问题?

@lduffy69
Copy link
Author

lduffy69 commented Feb 8, 2021

AbstractBeanFactory

	ResolvableType getTypeForFactoryBeanFromAttributes(AttributeAccessor attributes) {
                 //注册Reference beanDefination时,是否可以设置目标类型
		Object attribute = attributes.getAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE);
		if (attribute instanceof ResolvableType) {
			return (ResolvableType) attribute;
		}
		if (attribute instanceof Class) {
			return ResolvableType.forClass((Class<?>) attribute);
		}
		return ResolvableType.NONE;
	}

@AlbumenJ AlbumenJ added the help wanted Extra attention is needed label Feb 10, 2021
@kylixs
Copy link
Member

kylixs commented Apr 9, 2021

AbstractBeanFactory

	ResolvableType getTypeForFactoryBeanFromAttributes(AttributeAccessor attributes) {
                 //注册Reference beanDefination时,是否可以设置目标类型
		Object attribute = attributes.getAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE);
		if (attribute instanceof ResolvableType) {
			return (ResolvableType) attribute;
		}
		if (attribute instanceof Class) {
			return ResolvableType.forClass((Class<?>) attribute);
		}
		return ResolvableType.NONE;
	}

It is very good, simpler than decorated definition! But it is available since Spring 5.2, cannot be used in Spring 4.x .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants