0

I am trying to call the functions "beforeApprovingCCTransactions" and "afterApprovingCCTransactions" while "creditCardAmountBorrowedUpdation(..)" is triggered. The function is not getting triggered. Below is the snippet from XML.

File 1 :

package Logger;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

public class AuthorizeCCTransactionsLogs {

public void beforeApprovingCCTransactions() {
    System.out.println("Going to begin transaction for Credit Card");
}

public void afterApprovingCCTransactions() {
    System.out.println("Going to end transaction for Credit Card");
}

}

File 2:

package AuthorizeCCTransactions;

public class CreditCardHelper {

public void creditCardAmountBorrowedUpdation(CreditCardBean retievedCreditCardBean , double amount ) throws ClassNotFoundException {
    retievedCreditCardBean.setAmount(retievedCreditCardBean.getAmount() + amount);
    CreditCardTransactionsDao creditCardTransactionsDao = new CreditCardTransactionsDao();
    creditCardTransactionsDao.update(retievedCreditCardBean);
}
}

Project Structure

XML File

  • bhai pura code post karo – saurabh kumar May 11 '20 at 08:58
  • @saurabhkumar I have given the code – Dipanjan Sengupta May 11 '20 at 10:25
  • From the configuration xml shared you have not enabled spring aop. Add `` to `context.xml` and retry. – R.G May 11 '20 at 16:19
  • If that does not work , please share a reproducible example with relevant classes. It is hard to go through images and do guess work to identify an issue. – R.G May 11 '20 at 16:21
  • @R.G Nor Working, check my git hub code.https://github.com/DipanjanSG/BankingApp/tree/master/src/main/java . The context.xml file is in the path BankingApp/src/main/java/configs/context.xml – Dipanjan Sengupta May 14 '20 at 12:31
  • Spring AOP can only advice bean method calls. The code creates an [instance](https://github.com/DipanjanSG/BankingApp/blob/master/src/main/java/BusinessLogic/AuthorizeCCTransactions.java#L82) of `CreditCardHelper` with `new` operator which is not a spring container managed bean. Configure the `CreditCardHelper` as a bean and obtain the same from application context for AOP to work. Also the naming convention followed is not per java standards and [ContextBeans](https://github.com/DipanjanSG/BankingApp/blob/master/src/main/java/configs/ContextBeans.java) is not the correct method to follow. – R.G May 14 '20 at 12:46
  • Please refer the [documentation](https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-dependencies) for more details – R.G May 14 '20 at 12:46
  • @R.G Thanx a ton buddy , I hav created a bean for CreditCardHelper. Let me know what to do about the "ContextBeans" Naming convention. – Dipanjan Sengupta May 15 '20 at 05:43
  • @R.G Can you check this issue? https://stackoverflow.com/questions/61910080/property-driverclassname-threw-exception-nested-exception-is-java-lang-nosuch – Dipanjan Sengupta May 20 '20 at 14:31

0 Answers0