I have a class Wallet
that extends a third party class. This class has an autowired service that is null when i try to use. Why can't spring find this service?
@Component
public class Wallet extends TRXService {
@Autowired
private TransactionsService transactionsService; //should be autowired
private static Logger logger = LoggerFactory.getLogger(Wallet.class.getName());
JSONObject message;
private String trxcode;
private String operation;
public Wallet(String payload) {
message = new JSONObject(payload);
}
//@Override
public void run() {
//process payload
try {
logger.info("Wallet|" + message);
trxcode = message.getJSONObject("header").getString("code");
operation = message.getJSONObject("header").getString("operation");
logger.info("Executing operation " + operation+ "with code " +trxcode);
if(trxcode.equals("0000")) {
transactionsService.deposit(message);//<----throws NullPointerException
}else if (trxcode.equals("00001")) {
transactionsService.transfer(message);
}else if (trxcode.equals("0002")) {
transactionsService.payment(message);
}else {
logger.error("transaction code not identified");
}
//this.respond(message, "0000", "Success");
}
catch (Exception ex) {
logger.error(ex.toString());
}
}
}
class injecting Wallet:
@Component
public class WalletProcessor {
@Autowired
private Wallet wallet;
private static Logger logger = LoggerFactory.getLogger(Wallet.class.getName());
@Override
public void afterPropertiesSet() {
try {
wallet.init(logger);
} catch (Exception ex) {
logger.error(ex.toString());
}
}
}