Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Templating has it's limits. However your problem can be solved very elegantly with Aspect. ( <a href="http://www.eclipse.org/aspectj/" rel="nofollow">http://www.eclipse.org/aspectj/</a> ) Just create a new annotation for every type of "template-case" you need and use an around advice.</p> <p><em>Ps: don't use printStackTrace() to syserr/sysout. There are so many production grade, lightweight logging frameworks.... pleeeaseee... don't abuse poor little System.out/err :)</em></p> <p>EDIT:</p> <p>Some example for a logging / benchmarking advice. <em>(note: I'm using spring AOP for aspects, and lombok for easy access to the logging framework. The <code>getCurrentUser()</code> code is not really relevant here, it's just for getting the current user from Spring Security)</em></p> <pre><code>package com.XXXXXXXX.aspects; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Component; @Component @Aspect @Slf4j public class LoggerAspect { private final static String DOMAIN = "XXXXXXXX"; private static String getCurrentUser() { String username = "Unknown"; try { Object principal = SecurityContextHolder.getContext(). getAuthentication(). getPrincipal(); if (principal instanceof UserDetails) { username = ((UserDetails) principal).getUsername(); } else { username = principal.toString(); } } catch (Exception e) { } return username; } @Pointcut("within(com.XXXXXXXX.services..*)") public void inServiceLayer() { } @Pointcut("execution(* getMatcherInfo(..)) || execution(* resetCounter(..))") public void notToAdvise() { } @Around("com.XXXXXXXX.aspects.LoggerAspect.inServiceLayer() &amp;&amp; !com.XXXXXXXX.aspects.LoggerAspect.notToAdvise()") public Object doLogging(ProceedingJoinPoint pjp) throws Throwable { long start = System.nanoTime(); StringBuilder sb = new StringBuilder(DOMAIN); sb.append('/'). append(getCurrentUser()). append(" accessing "). append(pjp.getSignature(). getDeclaringTypeName()). append('.'). append(pjp.getSignature(). getName()); log.trace("START: " + sb.toString()); Object retVal = pjp.proceed(pjp.getArgs()); long duration = System.nanoTime() - start; log.trace("STOP: " + duration / 1000000 + " msec. " + sb.toString()); return retVal; } } </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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