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

Configure taglib with spring #2

Closed
tveimo opened this issue May 24, 2015 · 10 comments
Closed

Configure taglib with spring #2

tveimo opened this issue May 24, 2015 · 10 comments
Assignees
Milestone

Comments

@tveimo
Copy link

tveimo commented May 24, 2015

It would be very convenient if the taglib could be configured through Spring. This is especially handy when the wro4j filter and manager is itself configured through Spring.

@tveimo
Copy link
Author

tveimo commented May 24, 2015

Maybe an instance of OptimizedResourcesRootProvider could be configured through spring?

@lifus lifus self-assigned this May 24, 2015
@lifus lifus closed this as completed in abffca0 May 24, 2015
@lifus lifus reopened this May 24, 2015
@lifus lifus added this to the v0.1.3 milestone May 24, 2015
@tveimo
Copy link
Author

tveimo commented May 25, 2015

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.

@lifus
Copy link
Member

lifus commented May 25, 2015

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.

@tveimo
Copy link
Author

tveimo commented May 25, 2015

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

@lifus
Copy link
Member

lifus commented May 25, 2015

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.

@tveimo
Copy link
Author

tveimo commented Jun 23, 2015

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.

@lifus
Copy link
Member

lifus commented Jun 23, 2015

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.

@tveimo
Copy link
Author

tveimo commented Jun 24, 2015

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/";
}
}

lifus added a commit that referenced this issue Jun 30, 2015
… that it would be possible to configure it from wro.properties

Relates to #2
lifus added a commit that referenced this issue Jun 30, 2015
lifus added a commit that referenced this issue Jul 2, 2015
@tveimo
Copy link
Author

tveimo commented Jul 6, 2015

Works well with 0.1.3-SNAPSHOT, thx!

@lifus
Copy link
Member

lifus commented Nov 21, 2015

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

@lifus lifus closed this as completed Nov 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants