dimanche 28 juin 2015

@Inject and @PostConstruct not worked in singleton pattern

I have a class as below:

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;
    }
}

When I call

UserAuthenticator authenticator = UserAuthenticator.getInstance();

init() method isn't called and userRepository is null

My web application run in JBOSS EAP 6.3

Can somebody help me!!

Aucun commentaire:

Enregistrer un commentaire