Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflections doesnt catch all classes with specified annotation. #471

Open
kyaaMiya opened this issue Nov 13, 2023 · 0 comments
Open

Reflections doesnt catch all classes with specified annotation. #471

kyaaMiya opened this issue Nov 13, 2023 · 0 comments

Comments

@kyaaMiya
Copy link

kyaaMiya commented Nov 13, 2023

I'm pretty sure its some kind of configuration error, but i'm not sure where and how to fix it, so maybe someone with more experience can help.
I implemented a kind of BeanRef, that at application start uses Reflections to search all classes in package de.app.appserver.persistence.dao.impl and below, that are annotated with @DAO and saves them to a map with the respective entity class as their key. It mostly works exactly how i want, but for some reason it cant detect my base dao implementation.

Here is my class hierachy for daos:

de.app.appserver.persistence.dao.iface.CommonDao.java
de.app.appserver.persistence.dao.iface.entity.EntityDao.java
de.app.appserver.persistence.dao.impl.GenericBaseDao.java
de.app.appserver.persistence.dao.impl.entity.EntityDaoImpl.java

Interfaces:

public interface CommonDao {
    //dao methods
}


public interface EntityDao extends CommonDao {
    //dao methods
}

Classes:

@DAO(AbstractPersistentEntity.class)
public class GenericBaseDao implements CommonDao {
    //dao method implementations
}


@DAO(Entity.class)
public class EntityDaoImpl extends GenericBaseDao implements CommonDao {
    //dao method implementations
}

StaticBeanRef:

public class StaticBeanRef {
    public static void registerDaos() {
        logger.info("registering daos...");
        Reflections ref = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("de.app.appserver.persistence.dao.impl")));
        Set<Class<?>> daoClasses = ref.getTypesAnnotatedWith(DAO.class);

        //retrieve dao instances via daoClasses and save them
    }
}

From my understanding, this should yield the classes "GenericBaseDao.class" and "EntityDaoImpl.class", but it only returns "EntityDaoImpl.class". Its not a huge problem, i can just add "GenericBaseDao.class" manually, but it bugs me that its no working how i want.

Does anyone know why this is happening? I did a little debugging, but its late so didnt get to far. What i found is, the Reflections objects TypedAnnotationsScanner store contains a whole lot of other classes, that arent even part of the configured package path.

Any insight would help my coding ocd ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant