我想为某些默认用户设置创建一个制作者注释。我想为每个新用户创建注入这些设置。但我的设置始终为null
。为什么呢?
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({FIELD,METHOD,PARAMETER,TYPE})
public @interface DefaultSettings {
}
public class UserSettings {
public UserSettings() {}
@Produces
@DefaultSettings
@RequestScoped
public UserSettings getDefaultSettings() {
UserSettings settings = new UserSettings();
settings.doSomeConfiguration();
return settings;
}
private void doSomeConfiguration() {
//default initialisation
}
}
class User {
@Inject
@DefaultSettings
private UserSettings settings; //always null
}
这里有什么问题或缺失?