Note that there are some explanatory texts on larger screens.

plurals
  1. POAspectJ code works only when running through junit
    primarykey
    data
    text
    <p>I am implementing logging using AspectJ and currently have 2 issues;</p> <ol> <li><p>My junit code executes the aspectj code and writes to external log file, but when deploying it in tomcat/running under server, nothing gets logged except the server start up data. I tried debugging it, the aspectj code is not getting hit when ran under server, but it does through junit. Is there some config settings I am missing?</p></li> <li><p>When I use <code>@Around</code> annotation, my junit fails since the control is switched back and forth between the method getting executed and the <code>Aspect</code> class thereby losing data in the POJO. I had to use <code>@Before</code> and <code>@After</code> to resolve this issue.The data is read from db in the DAO and then the control gets transferred to the <code>Aspect</code> class and then it gets dropped before it gets back to the junit DaoTest class thereby causing a null pointer exception. Whats the right way to address this scenario?</p></li> </ol> <p>This is my LoggingAspect class:</p> <pre><code>static Logger log = Logger.getLogger(LoggingAspect.class.getName()); @Before("execution(* com.ams.simulator.service.*.*(..))") public void BeforeExecution(JoinPoint joinPoint) { log.info("----------------------------------------------------------"); log.info("Entering method : " + joinPoint.getSignature().getName()); log.info("----------------------------------------------------------"); } @After("execution(* com.ams.simulator.service.*.*(..))") public void AfterExecution(JoinPoint joinPoint) { log.info("----------------------------------------------------------"); log.info("Exiting method: " + joinPoint.getSignature().getName()); log.info("----------------------------------------------------------"); } @Around("execution(* com.ams.simulator.service.*.*(..))") public void AroundExecution(ProceedingJoinPoint joinPoint) throws Throwable { log.debug("This method was injected before executing " + joinPoint.getSignature().getName()); // System.out.println("This method was injected before executing " // + joinPoint.getSignature().getName()); joinPoint.proceed(); log.debug("This method was injected after executing " + joinPoint.getSignature().getName()); // System.out.println("This method was injected after executing " // + joinPoint.getSignature().getName()); } </code></pre> <p>Junit:</p> <pre><code>@Test public void getAllOid() { List&lt;Oid&gt; oidList = impl.getOidList(); //this returns null for (Oid value : oidList) { System.out.println("Oid Get is :" + value.getOid_get()); } System.out.println(oidList.size()); } </code></pre> <p>DAO:</p> <pre><code>public List&lt;Oid&gt; getOidList() { List&lt;Oid&gt; result = new ArrayList(); try { session = getSessionFactory().openSession(); transaction = session.beginTransaction(); Criteria criteria = session.createCriteria(Oid.class); result = criteria.list(); } catch (Exception e) { System.out.println("Exception occured :" + e.getMessage()); } transaction.commit(); return result;//this returns data from db } </code></pre> <p>The result returns data from db but gets lost before reaching the junit class.</p> <p>I am using jdk-1.7, maven 3.1.1, spring 3.1.0 if that helps and eclipse juno 64bit.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload