I’ve moved to xml config to JavaConfig. Now my vaadin UI is not working. Is it possible to configure vaadin without applicationcontext.xml?
Here is my configuration code -
public class MvcWebApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
// Load database and spring security configuration
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
// TODO Auto-generated method stub
super.onStartup(servletContext);
}
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] {WebSecurityConfig.class, HibernateConfiguration.class};
}
// Load spring web configuration
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] {WebMvcConfig.class};
}
@Override
protected String[] getServletMappings() {
return new String[] {"/"};
}
@Override
protected Filter[] getServletFilters() {
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
return new Filter[] {characterEncodingFilter, new DelegatingFilterProxy("springSecurityFilterChain")};
}
@Override
protected void registerContextLoaderListener(ServletContext arg0) {
arg0.setInitParameter("webAppRootKey", "shopbeat.root");
arg0.addListener(WebAppRootListener.class);
arg0.addListener(RequestContextListener.class);
super.registerContextLoaderListener(arg0);
}
}
Below is my vaadin starter servlet -
@Push(PushMode.MANUAL)
@JavaScript({"https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js", "vaadin://../assets/js/jquery.mp3.js", "vaadin://../assets/js/admin.js"})
@StyleSheet({"vaadin://../assets/css/player.css", "vaadin://../assets/css/custom.css"})
@Theme("skyadmin")
@PreserveOnRefresh
@SpringUI
public class SkyAdminApplication extends UI implements Broadcaster.BroadcastListener {
private static final long serialVersionUID = -8851261841287750333L;
public static final long TIME_EDGE = 259200L;
// The main application window. All components are embedded in this object.
private SkyAdminApplication instance;
private static Logger log = Logger.getLogger(SkyAdminApplication.class);
private boolean stop = false;
// The context - store all data related to logged in user here
private Context context = null;
@EnableVaadin
@Configuration
public static class MyConfiguration {
}
static {
Thread.setDefaultUncaughtExceptionHandler(new SkyAdminUncaughtExceptionHandler());
}
@Override
protected void init(VaadinRequest request) {
setWidthUndefined();
UI.getCurrent().getPage().setTitle("Admin");
setResponsive(true);
// Close the application if the main window is closed.
context = new Context();
UI.getCurrent().addWindow(new LoginWindow(this));
instance = this;
Broadcaster.register(this);
}
// @return the current application instance
public SkyAdminApplication getInstance() {
return instance;
}
public Context getSkyAdminContext() {
return context;
}
@WebServlet(urlPatterns = {"/app", "/app/*", "/VAADIN/*"}, name = "SkyAdminApplicationServlet", asyncSupported = true,
initParams = {@WebInitParam(name = "org.atmosphere.useBlocking", value = "true")})
@VaadinServletConfiguration(ui = SkyAdminApplication.class, productionMode = true)
public static class MyUIServlet extends SpringVaadinServlet {
private static final long serialVersionUID = 6823788931438099843L;
}
@Override
public void detach() {
Broadcaster.unregister(this);
super.detach();
}
@Override
public void receiveBroadcast(String message) {
access(() -> Notification.show(message, Type.ERROR_MESSAGE));
}
}
I’ve created Bean of MyConfiguration class-
@Configuration
@EnableAspectJAutoProxy
@EnableScheduling
@PropertySource("classpath:shopbeat.properties")
@ComponentScans(value = {@ComponentScan("com.skynetwork.entity"), @ComponentScan("com.skyadmin.web.config"), @ComponentScan("com.skyadmin.web.listeners"),
@ComponentScan("com.skyadmin.web.servlets"), @ComponentScan("com.skyadmin.web.controller"), @ComponentScan("com.skyadmin.web.application"),
@ComponentScan("com.skyadmin.web.ws"), @ComponentScan("con.skyadmin.web.skynetwork")})
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Bean
public MyConfiguration getMyConfiguration() {
return new MyConfiguration();
}
}
Please help how can i fix the issue?