Skip to content

AutowiredAnnotationBeanPostProcessor made mistake to check the bean is unique [SPR-10106] #14739

@spring-projects-issues

Description

@spring-projects-issues

jerryscott opened SPR-10106 and commented

I create the self annotation with @Qualifier(spring provided) like this:
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface MsgDefineQualifier {
ChannelType channelType();
}

then I create 2 beans in @Configuration bean like this:
@MsgDefineQualifier(channelType = ChannelType.E_POS)
@Bean
public IChannelMsgDefine getPosChannelMsgDefine() {
return new IChannelMsgDefine() {

		@Override
		public Sign getMsgSign() {
			return Sign.MD5;
		}

		@Override
		public Charset getMsgCharset() {
			return Charset.UTF_8;
		}

		@Override
		public Format getMsgFormat() {
			return Format.JSON;
		}

		@Override
		public Cipher getMsgCipher() {
			return Cipher.NON;
		}

		@Override
		public Compress getMsgCompress() {
			return Compress.FLATOR;
		}

	};
}

    @MsgDefineQualifier(channelType = ChannelType.P_GATE)
@Bean
public IChannelMsgDefine getEGateChannelMsgDefine() {
	return new IChannelMsgDefine() {

		@Override
		public Sign getMsgSign() {
			return Sign.MD5;
		}

		@Override
		public Charset getMsgCharset() {
			return Charset.GBK;
		}

		@Override
		public Format getMsgFormat() {
			return Format.PURE;
		}

		@Override
		public Cipher getMsgCipher() {
			return Cipher.RPC;
		}

		@Override
		public Compress getMsgCompress() {
			return Compress.NON;
		}

	};
}

but once I want to inject some of the bean in other place like this:

@MsgDefineQualifier(channelType = ChannelType.P_GATE)
@Autowired
private IChannelMsgDefine eGateChannelMsgDefine;

spring3.2 GA throw exception in such trace:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.congoal.channel.msg.protocol.IChannelMsgDefine] is defined: expected single matching bean but found 2: [getPosChannelMsgDefine, getEGateChannelMsgDefine]

particularly in linux enviroment(jdk version is : 1.6.0_37) while not occruing in windowx(that's very strange).

The attachment shows the part of the stack trace.


Affects: 3.2 GA

Attachments:

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions