【发布时间】:2015-06-28 09:25:00
【问题描述】:
我有一门课如下:
public class UserAuthenticator {
private static UserAuthenticator authenticator =
@Inject
private UserRepository userRepository;
@PostConstruct
public void init() {
List<User> allUsers = userRepository.findAll();
for (User user : allUsers) {
users.put(user.getEmail(), user.getPassword());
serviceKeys.put(user.getServiceKey(), user.getEmail());
}
}
public static UserAuthenticator getInstance() {
if (authenticator == null) {
authenticator = new UserAuthenticator();
}
return authenticator;
}
}
当我打电话时
UserAuthenticator authenticator = UserAuthenticator.getInstance();
init() 方法未被调用且 userRepository 为 null
我的 Web 应用程序在 JBOSS EAP 6.3 中运行。
这是怎么引起的,我该如何解决?
【问题讨论】:
标签: java jakarta-ee dependency-injection singleton postconstruct