First of all, I don't think com.validation.ValidateCharacteristicsProcessor
exist in your project. Still if you are trying to load that class (if present), then check whether this class is annotated with @Fix
or not.
I'm showing with TestClass that you have provided.
I tried a simple approach.
First, I created a simple maven project to demonstrate two approaches.
Using Java Reflections.
Using Spring Core as you are using it in the Test method.
Project Structure :

Fix.java
package com.example;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Retention(RUNTIME)
@Target(TYPE)
public @interface Fix {
public String[] author() default "";
}
TestClass.java
package com.example;
@Fix(author = "John Doe")
public class TestClass {
public void test() {
}
}
Main.java
package com.example;
public class Main {
public static void main(String[] args) throws ClassNotFoundException {
// create an instance of TestClass
TestClass t = new TestClass();
// use reflection to extract annotation from TestClass.class
Fix fix = t.getClass().getAnnotation(Fix.class); // or TestClass.class.getAnnotation(Fix.class);
// print the value
System.out.println(fix.author()[0]);
}
}
Output :

If you want to carry on with the code that you have provided, then I have a fix given below.
I have researched about ResourcePatternResolver
and I think you are using spring-core
to read classes.
So, I have updated your code.
package com.example;
import java.io.IOException;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
public class Main {
public static void main(String[] args) throws ClassNotFoundException {
ResourcePatternResolver resolversec = new PathMatchingResourcePatternResolver();
Class<?> cl = resolversec.getClassLoader().loadClass("com.example.TestClass");
if (cl != null) {
System.out.println("Class is not null " + cl.getSimpleName());
}
Fix fix = cl.getAnnotation(Fix.class);
if (fix != null) {
System.out.println("!!!! " + fix.author()[0]);
}
}
}
Output :

pom.xml
:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>read-annotations</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>