I don't think that this has anything to do with Singletons. The annotation @Alternative just is not meant to be used on Producer classes, but on the alternative implementation of a bean. You could use a alternative stereotype and annotate your alternative producer method instead to make this work. This is needed, because methods that have @Alternative annotation can't be enabled in beams.xml - but stereotypes can (see also this discussion on JBoss forum). To do so, you have to create a stereotype like this:
@RequestScoped
@Stereotype
@Retention(RetentionPolicy.RUNTIME)
@Alternative
@Target({
ElementType.TYPE, ElementType.METHOD
})
public @interface Staging {}
You have to enable this alternative stereotype in your beans.xml (instead declaring your alternative producer class there) like this:
<alternatives>
<stereotype>full.qualified.path.to.Staging</stereotype>
</alternatives>
You can then annotate your alternative producer method (best you delete the @Alternative annotation on your producer class and in the beans.xml):
@Singleton
public class ProducersAlternative {
@Produces @Named(PREFERENCES_FILE_NAMED) @Staging
public String producePreferenceFileName(){
return "preferences_test.xml";
}
}
Hope this helps :-)