Search code examples
javastripes

How to get all actionbean classes at contextInitialized()


A similar question is answered here: Stripes 1.5 - any way to ask the system for a list of all ActionBeans? it seems only work in an actionbean code, i.e: when it actually receives a request.
What I want is to list all actionbeans in contextListener code, for instance contextInitialized() function. Error happened:

net.sourceforge.stripes.exception.StripesRuntimeException: Something is trying to access the current Stripes configuration but the current request was never routed through the StripesFilter! As a result the appropriate Configuration object cannot be located. Please take a look at the exact URL in your browser's address bar and ensure that any requests to that URL will be filtered through the StripesFilter according to the filter mappings in your web.xml.
    at net.sourceforge.stripes.controller.StripesFilter.getConfiguration(StripesFilter.java:160)
    at net.sourceforge.stripes.util.CryptoUtil.encrypt(CryptoUtil.java:123) 

My purpose is to automatically initialize all the plug-in classes added later, without maintaining a list of all actionbeans somewhere in the code. Any suggestion? (or, at least, is it possible to do so?)
Best Regards,


Solution

  • OK. After a while, I figured out the solution: using Stripes ResolverUtil

    ResolverUtil<ActionBean> resolver = new ResolverUtil<ActionBean>();
    resolver.findImplementations(ActionBean.class, "my.base.package");
    Set<Class<? extends ActionBean>> beans = resolver.getClasses();
    

    Thanks!