Skip to content

Commit

Permalink
fix: use default impl if app context is not available in config facto…
Browse files Browse the repository at this point in the history
…ry (#709)

Details: fixes the case when the web app context is not yet available for deployable WAR.
  • Loading branch information
Denis authored Dec 28, 2020
1 parent fff2025 commit b26eec5
Showing 1 changed file with 2 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
package com.vaadin.flow.spring;

import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.vaadin.flow.server.VaadinContext;
Expand All @@ -41,20 +36,6 @@
public class SpringApplicationConfigurationFactory
extends DefaultApplicationConfigurationFactory {

@Component
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
private static class AppContextHolder {

@Autowired
private ApplicationContext context;

private static AtomicReference<AppContextHolder> self = new AtomicReference<>();

private AppContextHolder() {
self.set(this);
}
}

@Override
protected ApplicationConfigurationImpl doCreate(VaadinContext context,
FallbackChunk chunk, Map<String, String> properties) {
Expand All @@ -65,10 +46,9 @@ protected ApplicationConfigurationImpl doCreate(VaadinContext context,
ApplicationContext appContext = WebApplicationContextUtils
.getWebApplicationContext(servletContext.getContext());
// sometimes for deployable WAR (couldn't find exact circumstances) the
// web app context is not yet available here, let's use a hack to get an
// app context from Spring singelton bean
// web app context is not yet available here
if (appContext == null) {
appContext = AppContextHolder.self.get().context;
return super.doCreate(context, chunk, properties);
}
Environment env = appContext.getBean(Environment.class);
// Collect any vaadin.XZY properties from application.properties
Expand Down

0 comments on commit b26eec5

Please sign in to comment.