Skip to content

Decouple o.s.w.reactive.result.view.UrlBasedViewResolver from ApplicationContext [SPR-15219] #19784

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

Closed
spring-projects-issues opened this issue Feb 3, 2017 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: task A general task
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 3, 2017

Toshiaki Maki opened SPR-15219 and commented

Router functions are actually available without ApplicationContext for very small footprint applications, but UrlBasedViewResolver calls getApplicationContext().getAutowireCapableBeanFactory().
This causes NullPointerException if i use router functions and freemaker without ApplicationContext.

private View applyLifecycleMethods(String viewName, AbstractView view) {
     return (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, viewName);
}

private View applyLifecycleMethods(String viewName, AbstractView view) {
return (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, viewName);
}

I'd be happy if these are decoupled.

Easiest way might be using lifecycleMethods as a BiFunction like following:

	private BiFunction<String, AbstractView, View> lifecycleMethods = (viewName,
			view) -> (View) getApplicationContext().getAutowireCapableBeanFactory()
					.initializeBean(view, viewName);

	public void setLifecycleMethods(
			BiFunction<String, AbstractView, View> lifecycleMethods) {
		this.lifecycleMethods = lifecycleMethods;
	}

	private View applyLifecycleMethods(String viewName, AbstractView view) {
		return lifecycleMethods.apply(viewName, view);
	}

I'm using this hack as a workarround.

https://github.com/making/ik.am/tree/622b1c289ea4273210d4bc0a1a905fa890e8b1b7/src/main/java/am/ik/FreeMarkerConfig.java
https://github.com/making/ik.am/blob/622b1c289ea4273210d4bc0a1a905fa890e8b1b7/src/main/java/org/springframework/web/reactive/result/view/UrlBasedViewResolver.java


Affects: 5.0 M4

Issue Links:

Referenced from: commits 14161d1

1 votes, 3 watchers

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jun 12, 2017

Juergen Hoeller commented

This has effectively been dealt with as part of #20099 already, conditionally using the ApplicationContext when available in both variants of UrlBasedViewResolver (in spring-webmvc as well as spring-webflux).

Additionally, I've moved the ApplicationContext field down from ViewResolverSupport to UrlBasedViewResolver since it's only really meant to be used for View class initialization there, leaving ViewResolverSupport as a more generic view property holder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: task A general task
Projects
None yet
Development

No branches or pull requests

2 participants