Skip to content

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

Closed
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: taskA general task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions