dependency isnt injected into my service

hey guys. can smb help me out. i have a service
@Service
@Slf4j
public class MyService {

ImportService importService;
CustomerRepository customerRepository;
PaymentRepository paymentRepository;
AppConfig appConfig;

public MyService (ImportService importService, CustomerRepository customerRepository, PaymentRepository paymentRepository) {
this.importService = importService;
this.customerRepository = customerRepository;
this.paymentRepository = paymentRepository;
}
public void createPaymentpaymentConfirmation(PaymentDTO paymentConfirmationRequest) throws NoEarlierPaymentException, JAXBException, IOException {
log.info(appConfig.getSystemUserId());
}
@Service
@Slf4j
public class MyService {

ImportService importService;
CustomerRepository customerRepository;
PaymentRepository paymentRepository;
AppConfig appConfig;

public MyService (ImportService importService, CustomerRepository customerRepository, PaymentRepository paymentRepository) {
this.importService = importService;
this.customerRepository = customerRepository;
this.paymentRepository = paymentRepository;
}
public void createPaymentpaymentConfirmation(PaymentDTO paymentConfirmationRequest) throws NoEarlierPaymentException, JAXBException, IOException {
log.info(appConfig.getSystemUserId());
}
and i get a NPE, bc smth is wrong with appconfig object. can smb help me out? thx
7 Replies
JavaBot
JavaBot5mo ago
This post has been reserved for your question.
Hey @bambyzas! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Peter Rader
Peter Rader5mo ago
Please show the Exception.
bambyzas
bambyzasOP5mo ago
i fixed it by injecting the appConfig into MyService. but now i have a question about making the injected fields private and final do i really need to?
Peter Rader
Peter Rader5mo ago
Hey FF, yes I did not noticed it either. It must have thrown a NPE. For the private-final question, pease open up a new question.
bambyzas
bambyzasOP5mo ago
my apologies. thank you
JavaBot
JavaBot5mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot5mo ago
Post Closed
This post has been closed by <@611623200756989972>.
Want results from more Discord servers?
Add your server