mercredi 14 mars 2018

Class.forName() with Spring Boot application, ClassCastException

I am trying to create instances of a class in SpringBootApplication using reflection. To achieve the same I am trying to get a 'Class' object using the Class.forName(String ClassName) method but it throws me a ClassCastException with nested ClassNotFoundException. I have a faint idea that Spring Boot has its own classloader and it's not being able to locate my Java file despite it being in the main src folder. Is there any way to fix this?

    public static List<Object> createExcelBeans(List<LinkedList<String>> excelData, List<String> excelFields,
        String className)
        throws NumberFormatException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
        ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IOException {
    List<Object> pojoList = new LinkedList<Object>();
    /*
     * getting the class instance of the specified name
     */
    Class<?> pojoClass = Class.forName(className);





Aucun commentaire:

Enregistrer un commentaire