<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: K Adithyan</title>
    <description>The latest articles on DEV Community by K Adithyan (@adithyank).</description>
    <link>https://dev.to/adithyank</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F724592%2Fc3e8d600-a660-43f7-826f-d88c203c8bed.jpg</url>
      <title>DEV Community: K Adithyan</title>
      <link>https://dev.to/adithyank</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adithyank"/>
    <language>en</language>
    <item>
      <title>Evernote Anonymous logins</title>
      <dc:creator>K Adithyan</dc:creator>
      <pubDate>Sat, 04 Dec 2021 05:44:04 +0000</pubDate>
      <link>https://dev.to/adithyank/evernote-anonymous-logins-24mj</link>
      <guid>https://dev.to/adithyank/evernote-anonymous-logins-24mj</guid>
      <description>&lt;p&gt;Very often, I m receiving mail from Evernote like this...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GSv-11H3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qpksjjef27cm9usl3w6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GSv-11H3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qpksjjef27cm9usl3w6.png" alt="Image description" width="620" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I login to evernote and see in the &lt;code&gt;devices&lt;/code&gt; section, I am often seeing logins like below from different countries...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WU-QxU2F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1i5n6uyujax1v6b7h87v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WU-QxU2F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1i5n6uyujax1v6b7h87v.png" alt="Image description" width="698" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My Evernote login is through my google account.. In that case, how is these logins happening from other countries...?&lt;/p&gt;

&lt;p&gt;Is my google account compromised or it is some security flaw in evernote app...???&lt;/p&gt;

&lt;p&gt;How to identify this..?&lt;/p&gt;

</description>
      <category>evernote</category>
      <category>security</category>
      <category>googleaccount</category>
      <category>evernotelogin</category>
    </item>
    <item>
      <title>Custom Annotation Scanning with Spring Boot</title>
      <dc:creator>K Adithyan</dc:creator>
      <pubDate>Wed, 13 Oct 2021 04:31:08 +0000</pubDate>
      <link>https://dev.to/adithyank/custom-annotation-scanning-with-spring-boot-4g</link>
      <guid>https://dev.to/adithyank/custom-annotation-scanning-with-spring-boot-4g</guid>
      <description>&lt;p&gt;In &lt;code&gt;Java&lt;/code&gt; programming language, &lt;code&gt;annotation&lt;/code&gt; offers a super way for supplying meta information about our code. These meta information can be used by frameworks to decide the functionality of that particular feature. When you design a module or a feature, you can define your own annotations and your feature can use it to achieve the functionalities similar to the existing frameworks&lt;/p&gt;

&lt;p&gt;The information in the annotaion is made available to the runtime of the code in 2 ways.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using &lt;code&gt;annotation processor&lt;/code&gt;. Annotation Processors are called by java compiler to process the information given at the AnnotatedElements to generate new Java source files or other meta-data&lt;/li&gt;
&lt;li&gt;Scanning the annotations during the JVM startup and using Java reflection, the &lt;code&gt;AnnotatedElement&lt;/code&gt;s can be identified and we can create meta models accordingly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This article deals with the 2nd way of scanning the annotated classes from the classpath or methods or variables in the runtime and using it for our feature.&lt;/p&gt;

&lt;p&gt;There are libraries like &lt;a href="https://github.com/classgraph/classgraph"&gt;classgraph&lt;/a&gt; that can be used in java applications that do not use &lt;code&gt;spring framework&lt;/code&gt;. If your application do not use spring framework or spring boot, you can refer to the &lt;a href="https://github.com/classgraph/classgraph"&gt;classgraph&lt;/a&gt; library documentation and proceed.&lt;/p&gt;

&lt;p&gt;If your application uses spring framework, then you can use the below snippet and get the list of classes that have been annotated with a particular annotation&lt;/p&gt;

&lt;p&gt;If your custom annotation is &lt;code&gt;@MyCustomAnnotation&lt;/code&gt;, you can find all the classes which are annotated with annotation &lt;code&gt;@MyCustomAnnotation&lt;/code&gt;using the below function call&lt;/p&gt;

&lt;p&gt;&lt;code&gt;findAnnotatedClasses(MyCustomAnnotation.class, "com.abc.def.xyz")&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The packages list is given as varargs as it would enable neat code in the calling places.&lt;/p&gt;

&lt;p&gt;The implementation of &lt;code&gt;findAnnotatedClasses()&lt;/code&gt; method is given below. The class &lt;code&gt;ClassPathScanningCandidateComponentProvider&lt;/code&gt; of spring framework does the magic of scanning the entire classpath and returns us the Bean classes which have the annotation &lt;code&gt;@MyCustomAnnotation.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For spring framework to scan your class that has your custom annotation &lt;code&gt;@MyCustomAnnotation,&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;your class must be annotated with &lt;code&gt;@Component&lt;/code&gt; or the other spring annotations that make your class a managed component of Spring.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;findAnnotatedClasses&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Class&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;?&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Annotation&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;annotationType&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt; &lt;span class="n"&gt;packagesToBeScanned&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;ClassPathScanningCandidateComponentProvider&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ClassPathScanningCandidateComponentProvider&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addIncludeFilter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; 
    &lt;span class="nc"&gt;AnnotationTypeFilter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;annotationType&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

    &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HashSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;pkg&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;packagesToBeScanned&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
         &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BeanDefinition&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;beanDefs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;findCandidateComponents&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pkg&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
         &lt;span class="n"&gt;beanDefs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
             &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;map&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;BeanDefinition:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;getBeanClassName&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
             &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;forEach&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;ret:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring Application's main class below shows how to call this method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@SpringBootApplication&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SpringApp&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;CommandLineRunner&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Autowired&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;ClassScanner&lt;/span&gt; &lt;span class="n"&gt;classScanner&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;SpringApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SpringApp&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;annotatedClasses&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;classScanner&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;findAnnotatedClasses&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyCustomAnnotation&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"xyz.reachadi"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;annotatedClasses&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Annotated Class : "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The approach is very simple..... right?&lt;/p&gt;

&lt;p&gt;So, what next? Enhance your codes' readability by defining custom annotations and using them on your codes.&lt;/p&gt;

&lt;p&gt;The full working example of this blog is available in my &lt;a href="https://github.com/adithyank/tutorials/tree/main/spring-boot-tutorials/custom-annotation-scanner"&gt;github repository.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please refer to &lt;code&gt;readme.md&lt;/code&gt; for instructions on running the tutorial.&lt;/p&gt;

</description>
      <category>java</category>
      <category>annotation</category>
      <category>spring</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
