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

AbstractReactiveWebInitializer does not property initialize ApplicationContext [SPR-16290] #20837

Closed
spring-issuemaster opened this issue Dec 12, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Dec 12, 2017

José María Sola Durán opened SPR-16290 and commented

I have this class to start WebFlux context in my web application:

public class WebAppInitializer extends AbstractReactiveWebInitializer {
	@Override
	protected Class<?>[] getConfigClasses() {
		return Stream.of(AppConfig.class, SpringWebFluxConfig.class).toArray(size -> new Class<?>[size]);
	}
}

When start the context, I obtain this exception:

java.lang.IllegalStateException: org.springframework.context.annotation.AnnotationConfigApplicationContext@280d42a1 has not been refreshed yet

I think that the problem is in the method AbstractReactiveWebInitializer#onStartup() because not refresh context. In this previous version RELASE of Spring Framework, I use the now deprecated class AbstractAnnotationConfigDispatcherHandlerInitializer. This class HandlerInitializer refresh context in the method AbstractDispatcherHandlerInitializer#onStartup():

public class WebAppInitializer extends AbstractReactiveWebInitializer {
	
	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
	String servletName = getServletName();
		Assert.hasLength(servletName, "getServletName() must not return empty or null");

		ApplicationContext applicationContext = createApplicationContext();
		Assert.notNull(applicationContext,
				"createApplicationContext() did not return an application " +
				"context for servlet [" + servletName + "]");

		refreshApplicationContext(applicationContext);
[....]

I need help you. Thanks a lot!


Affects: 5.0.2

Issue Links:

  • #20633 Using AbstractAnnotationConfigDispatcherHandlerInitializer to run Spring Webflux application as a WAR doesn't work ("is duplicated by")
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 12, 2017

José María Sola Durán commented

Also, in method AbstractReactiveWebInitializer#createApplicationContext(), you don't use context.register() in order to add the config classes when you create the AnnotationConfigApplicationContext. The code is below:

protected ApplicationContext createApplicationContext() {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
		Class<?>[] configClasses = getConfigClasses();
		Assert.notEmpty(configClasses, "No Spring configuration provided.");
		return context;
	}

But, I think that the correct code is:

protected ApplicationContext createApplicationContext() {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
		Class<?>[] configClasses = getConfigClasses();
		Assert.notEmpty(configClasses, "No Spring configuration provided.");
                if (!ObjectUtils.isEmpty(configClasses)) {
			context.register(configClasses);
		}
		return context;
	}
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 9, 2018

Rossen Stoyanchev commented

This should be resolved now. Sorry for the trouble!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.