<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AOP &#8211; Pauls Blog</title>
	<atom:link href="https://sterl.org/tag/aop/feed/" rel="self" type="application/rss+xml" />
	<link>https://sterl.org</link>
	<description></description>
	<lastBuildDate>Wed, 09 Mar 2022 20:32:46 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
	<item>
		<title>Aspects with Annotations</title>
		<link>https://sterl.org/2021/05/aspects-with-annotations/</link>
					<comments>https://sterl.org/2021/05/aspects-with-annotations/#respond</comments>
		
		<dc:creator><![CDATA[Paul Sterl]]></dc:creator>
		<pubDate>Mon, 24 May 2021 09:28:46 +0000</pubDate>
				<category><![CDATA[AOP]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring Boot]]></category>
		<category><![CDATA[aspect]]></category>
		<guid isPermaLink="false">https://sterl.org/?p=655</guid>

					<description><![CDATA[Problem Define a pointcut for annotated methods. The most example are based only on @within or @annotation which has the downside that the aspect is added to all methods and the check of the annotation is executed during runtime. Solution Git Repository https://github.com/sterlp/training/tree/master/aspect Links https://www.eclipse.org/aspectj/doc/released/progguide/semantics-pointcuts.html https://docs.spring.io/spring-framework/docs/5.3.x/reference/html/core.html#aop-pointcuts-designators]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Problem</h2>



<p>Define a pointcut for annotated methods. The most example are based only on <code>@within</code> or <code>@annotation</code> which has the downside that the aspect is added to all methods and the check of the annotation is executed during runtime. </p>



<h2 class="wp-block-heading">Solution</h2>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}">@Aspect
@Component
public class MethodAspect {
    /**
     * This ensures that the aspect is only woven into methods with the annotation.
     * Otherwise all methods are woven!
     */
    @Pointcut(&quot;execution(@MethodAnnotation * * (..))&quot;)
    private void isAnnotated() {};
    /**
     * (optional) Limit package scan to our project only
     */
    @Pointcut(&quot;execution(* your.project.package..*(..))&quot;)
    private void isInPackage() {};

    @Around(&quot;isAnnotated() &amp;&amp; isInPackage() &amp;&amp; @annotation(annotation)&quot;)
    public Object logExecutionTime(ProceedingJoinPoint joinPoint, 
                                   MethodAnnotation annotation) throws Throwable {
        return joinPoint.proceed();
    }
}</pre></div>



<h2 class="wp-block-heading">Git Repository</h2>



<p><a href="https://github.com/sterlp/training/tree/master/aspect">https://github.com/sterlp/training/tree/master/aspect</a></p>



<h2 class="wp-block-heading">Links</h2>



<ul class="wp-block-list"><li><a href="https://www.eclipse.org/aspectj/doc/released/progguide/semantics-pointcuts.html">https://www.eclipse.org/aspectj/doc/released/progguide/semantics-pointcuts.html</a></li><li><a href="https://docs.spring.io/spring-framework/docs/5.3.x/reference/html/core.html#aop-pointcuts-designators">https://docs.spring.io/spring-framework/docs/5.3.x/reference/html/core.html#aop-pointcuts-designators</a></li></ul>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://sterl.org/2021/05/aspects-with-annotations/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
