Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring AOP pointcut definition for string setter
    primarykey
    data
    text
    <p>I'm developing an aspect that checks string arguments of setter methods of my entity package for empty strings and replace them with <code>null</code> values. But unfortunately my aspect doesn't works well :(. I guess it is because of my pointcut definition, but I'm not sure.</p> <p>My aspect looks like:</p> <pre><code>import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; @Aspect public class EmptyStringToNullSetter { private static final Logger LOGGER = LoggerFactory .getLogger(EmptyStringToNullSetter.class); public void check(final JoinPoint jp) { LOGGER.debug(jp.getSignature().toLongString()); } } </code></pre> <p>My spring config looks like:</p> <pre><code>&lt;bean id="emptyStringToNullSetter" class="de.foo.util.aop.parameter.EmptyStringToNullSetter" /&gt; &lt;aop:config&gt; &lt;aop:pointcut id="entityStringSetter" expression="execution(* de.foo.entity.*.set*(..)) and args(java.lang.String)" /&gt; &lt;aop:aspect id="checkEmptyStringsAspect" ref="emptyStringToNullSetter"&gt; &lt;aop:before method="check" pointcut-ref="entityStringSetter" /&gt; &lt;/aop:aspect&gt; &lt;/aop:config&gt; </code></pre> <p>My test class looks like:</p> <pre><code>import de.foo.entity.Period; @ContextConfiguration(locations = { "/spring/test-util-context.xml" }) public class EmptyStringToNullSetterTest extends AbstractJUnit4SpringContextTests { @Test public void testCheck() { Period period = new Period(); period.setName(""); Assert.assertNull(period.getName()); } } </code></pre> <p>When I execute my test the aspect doesn't intercept my setter. Do anyone has any idea why?!</p> <p>Cheers,</p> <p>Kevin</p>
    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. 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