Code Monkey home page Code Monkey logo

Comments (10)

tveimo avatar tveimo commented on July 1, 2024

Maybe an instance of OptimizedResourcesRootProvider could be configured through spring?

from wro4j-runtime-taglib.

tveimo avatar tveimo commented on July 1, 2024

If wro4j is configured through spring, then the filter is often an instance of the dynamic proxy class org.springframework.web.filter.DelegatingFilterProxy. Additionally, there's no instance of WroServletContextListener.

from wro4j-runtime-taglib.

lifus avatar lifus commented on July 1, 2024

WroManagerFactory should be initialized before TaglibContext because TaglibContextFactory decorates WroManagerFactory. i.e. WroServletContextListener might still be required to create WroManagerFactory unless there would be a singleton bean for WroManagerFactory that would be injected/autowired.

Unfortunately, DelegatingFilterProxy doesn't provide a way to get a bean class name(s) and so we couldn't be sure that it actually delegates to WroFilter. findWebApplicationContext is protected i.e. it would require some spring-specific code and I believe that there might be a better solution:

I'm going to support something like this:

optimizedResourcesRootStrategy=predefined
optimizedResourcesRoot=/wro/

this class should probably also have a setter to allow setter injection.

from wro4j-runtime-taglib.

tveimo avatar tveimo commented on July 1, 2024

Would it be an option to configure the TaglibContextFactory through spring as well?

from wro4j-runtime-taglib.

lifus avatar lifus commented on July 1, 2024

Actually, It might be already possible to initialize TaglibContext through spring because TaglibContext.initialize accepts ServletContext.
There is a prerequisite, though: WroManagerFactory should already be stored as an attribute. That's the reason why I suggested to use WroServletContextListener
Also, WroContextFilter is required to provide Context at runtime.

from wro4j-runtime-taglib.

tveimo avatar tveimo commented on July 1, 2024

Do you have an example setting up a TaglibContext in spring? The crucial constructors in TaglibContext and TaglibContextFactory are package protected, making it a bit hard to initialize outside.

from wro4j-runtime-taglib.

lifus avatar lifus commented on July 1, 2024

Unfortunately, I don't have such an example. I may create one though.
Constructors in TaglibContext and TaglibContextFactory are package protected because TaglibContext should be initialized through TaglibContext.initialize so that it would be possible to retrieve TaglibContext using TaglibContext.get
I'm not entirely sure how do you want to configure taglib with spring. I believe that one way to do it is to create ServletContextAware bean and initialize TaglibContext there. As I mentioned before, WroManagerFactory should be initialized before TaglibContext and "persisted" in ServletContext as well.

from wro4j-runtime-taglib.

tveimo avatar tveimo commented on July 1, 2024

Ok, got it set up now, but unfortunately, in DefaultOptimizedResourcesRootProvider.getFilterRegistrations(), servletContext.getServletRegistrations() is called, and this method cannot be called from outside of a servlet listener (throws an UnsupportedOperationException).

So I guess using a different resources root provider that just takes the config from properties as you suggested above is probably the best way forward. I had success with a dummy setup;

package com.github.lifus.wro4j_runtime_taglib.model.resource.uri.root;

import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import ro.isdc.wro.http.WroFilter;

public final class SpringOptimizedResourcesRootProvider extends AbstractOptimizedResourcesRootProvider {

public SpringOptimizedResourcesRootProvider(final ServletContext servletContext) { }

@OverRide
protected String findOutRoot() {
return "/resources/wro/";
}
}

from wro4j-runtime-taglib.

tveimo avatar tveimo commented on July 1, 2024

Works well with 0.1.3-SNAPSHOT, thx!

from wro4j-runtime-taglib.

lifus avatar lifus commented on July 1, 2024

Closing this one for now as I'm going to include current implementation as is in 0.2.0 release. Feel free to reopen this issue or create a more specific one

from wro4j-runtime-taglib.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.