NullPointerException when @Autowiring in AppUI.init (just on standalone/pro

Hello

I face problem I cannot solve.
Using:
vaadin 8.1.5
springboot 1.5.4
vaading4spring 2.0.0.RELEASE (tried also 0.0.7.RELEASE, same error)

My code:

@SpringUI
public class AppUI extends UI {

@Autowired
private MainScreen mainScreen;

@Override
protected void init(VaadinRequest request) {
Responsive.makeResponsive(this);
addStyleName(ValoTheme.UI_WITH_MENU);

final Navigator navigator = new Navigator(this, mainScreen.getContainer());
navigator.addProvider(viewProvider);
navigator.setErrorView(errorView);
navigator.addViewChangeListener(appViewChangeListener);
setScreen();

...
}}
@UIScope
@SpringComponent
public class MainScreen extends MainScreenDesign implements AppScreen {...}
@SpringBootApplication()
@Primary
public class LimsApplication extends SpringBootServletInitializer {

@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}

public static void main(String args) {
SpringApplication.run(LimsApplication.class, args);
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(LimsApplication.class);
}
}

Works when running on embedded tomcat via command spring-boot:run, application works,
but throws NullPointerException on production server or standalone, when deploying as WAR. (my packaging in pom.xml is WAR in both cases)

Both Tomcats are 8.5.15.

2017-12-06 17:52:10.918 INFO 4336 --- [nio-8080-exec-7]
 o.v.spring.servlet.Vaadin4SpringServlet : Custom Vaadin4Spring servlet initialization completed
2017-12-06 17:52:11.356 ERROR 4336 --- [nio-8080-exec-8]
 com.vaadin.server.DefaultErrorHandler :

java.lang.NullPointerException: null
at sk.geneton.lims.frontend.ui.AppUI.init(AppUI.java:101)
at com.vaadin.ui.UI.doInit(UI.java:745)

Attached you can find complete tomcat logs when starting on embedded tomcat and standalone tomcat.

I guess it’s something with vaadin and spring sessions, but cannot find solution.

Hope somebody helps me.

Michal Lichvar

39501.txt (50.4 KB)
39502.txt (157 KB)

Ok, we found the problem, it was in code below (static class at the end of AppUI, used to change system messages)

@WebServlet(urlPatterns = "/*", name = "CustomUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = AppUI.class, productionMode = false)
public static class CustomUIServlet extends VaadinServlet {

   @Override
   protected void servletInitialized() throws ServletException {
      super.servletInitialized();

      CustomizedSystemMessages messages = new CustomizedSystemMessages();

      // Internal Error (after JWT expired exception) overwritten to Connection Timeout
      messages.setInternalErrorCaption("Connection timeout");
      messages.setInternalErrorMessage("Take note of any unsaved data, and <u>click here</u> or press ESC to continue.");

      getService().setSystemMessagesProvider(e -> messages);

   }
}

solution: change VaadinServlet to SpringVaadinServlet :smiley: