-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
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:
- stacktrace.txt (3.99 kB)
Issue Links:
- Autowiring with @Qualifier and @Qualifier meta annotation fails in Spring 3.2 [SPR-10107] #14740 Autowiring with
@Qualifier
and@Qualifier
meta annotation fails in Spring 3.2 ("duplicates")