Annotation based configuration – performance

Splash Forums PrettyFaces Users Annotation based configuration – performance

This topic contains 4 replies, has 2 voices, and was last updated by  Christian Kaltepoth 9 years, 10 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #18252

    Petter Helset

    Hello, I’m experiencing some performance-issues when using “com.ocpsoft.pretty.SCAN_LIB_DIRECTORY” and “com.ocpsoft.pretty.BASE_PACKAGES”.

    The project I’m working on consists of multiple modules/projects (eg. in separated jars).

    The main module works as a container for the rest of the modules; it scans the jars (classpath) in WEB-INF/lib for spring-beans, faces-pages etc.

    This module is the actual war-file in the project – the other modules is just included jars.

    Simplified example:

    – project-hub (war)

    – user-services-web-api (jar)

    – news-services-web-api (jar)

    The hub contains web.xml, spring-config, faces-config, pretty-config (empty), etc.

    The web-api modules contains spring controllers, modules (components), faces-pages (xhtml), and so on.

    The hub scans for controllers, modules, etc.

    The user-controller may look like this:


    @URLMappings(mappings = {

    @URLMapping(id = LIST, pattern = "/secure/users/", viewId = "/faces/secure/user/list.xhtml"),

    @URLMapping(id = VIEW, pattern = "/secure/user/#{" + ID + "}/", viewId = "/faces/secure/user/view.xhtml")


    public class UserController {

    public static final String LIST = "user_list";

    public static final String VIEW = "user_view";

    public static final String ID = "id";

    /* autowiring etc. */

    @URLAction(mappingId = VIEW, onPostback = false)

    public void view() {

    final HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

    final Long userId = request.getParameter(ID);

    final User user = service.findUser(userId);



    /* ... */


    The user-model may look like this:


    @Scope(value = "view", proxyMode = ScopedProxyMode.TARGET_CLASS)

    public class UserModel implements Serializable {

    /* ... */

    private User user;

    /* plain getters and setters */


    The web.xml contains:









    The problem:

    It seems that EVERY time there is a request to the servlet, the annotation-scanner scans my packages and libs. This is a time-consuming process (the larger the lib folder is, the more time-consuming).

    Why isn’t the annotated mappings scanned ONCE, and then cached?

    (btw. this approach with @Controller and @Component w/@Scope is not the “JSF-way”, altho our preferred way – the classes annotated with @Controller is global-scoped for all requests)

    PrettyFaces 3.3.3

    JSF 2.1.6

    SpringFramework 3.1.0.RELEASE (core, webmvc and security)

    Apache Tomcat 7.0.26


    Hey phelset,

    PrettyFaces reloads it’s configuration on a regular basis to allow developers to update the configuration without restarting the server. But this is only done in project stage “development”. So this shouldn’t have any effect on production performance.

    But if I remember correctly you can disable this behavior by setting the following servlet context parameter in your web.xml:


    Does this solve your performance problem?



    Petter Helset

    Solved this by implementing a custom ConfigurationProvider and disabling both “com.ocpsoft.pretty.SCAN_LIB_DIRECTORY” and “com.ocpsoft.pretty.BASE_PACKAGES”.


    public PrettyConfig loadConfiguration(ServletContext servletContext)


    final ListableBeanFactory listableBeanFactory = WebApplicationContextUtils.getWebApplicationContext(servletContext);

    final Map<String, Object> controllers = listableBeanFactory.getBeansWithAnnotation(Controller.class);

    final LazyBeanNameFinder beanNameFinder = new LazyBeanNameFinder(servletContext);

    final PrettyAnnotationHandler annotationHandler = new PrettyAnnotationHandler(beanNameFinder);

    for (Object o : controllers.values())




    final PrettyConfigBuilder builder = new PrettyConfigBuilder();;



    This ConfigurationProvider finds all beans annotated with @Controller and processes PrettyFaces annotations with PrettyAnnotationHandler.


    Petter Helset

    Christian Kaltepoth, thanks – disabling development mode seems to speed it up :-)

    (also not calling ConfigurationProvider on every request)


    Nice to hear that it’s working for you now! :)

Viewing 5 posts - 1 through 5 (of 5 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.