Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Vaadin + Spring (Not Boot)
So I'm having issues with my project right now. I have this Vaadin with Spring project running in tomcat. Whenever I run it this exception occurs :
SEVERE: Servlet.service() for servlet [poc.spring.vaadin.dashboard.config.SpringVaadinServlet] in context with path [/dashboard] threw exception [com.vaadin.server.ServiceException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'poc.spring.vaadin.dashboard.DashboardUI': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.vaadin.spring.navigator.SpringViewProvider poc.spring.vaadin.dashboard.DashboardUI.springViewProvider; nested exception is java.lang.IllegalArgumentException: Found no valid com.vaadin.spring.internal.UIID instance!] with root cause
java.lang.IllegalArgumentException: Found no valid com.vaadin.spring.internal.UIID instance!
Stackoverflow Link to the same question http://stackoverflow.com/questions/42362018/vaadin-without-spring-boot-issue
Code as follows this is my AppConfig.java
@Configuration
@EnableVaadin
@EnableTransactionManagement
@ComponentScan(basePackages = "poc.spring.vaadin.dashboard.*")
@PropertySource(value = { "classpath:application.properties" })
public class AppConfig {
@Autowired
private Environment environment;
private static ApplicationContext ctx;
public static void setApplicationContext(ApplicationContext applicationContext) {
ctx = applicationContext;
}
public static ApplicationContext getApplicationContext() {
return ctx;
}
@Bean
public ApplicationContextProvider applicationContextProvider() {
ApplicationContextProvider applicationContextProvider = new ApplicationContextProvider();
return applicationContextProvider;
}
@Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan(new String { "poc.spring.vaadin.dashboard.entity" });
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
@Bean(name = "postgresDataSource")
@Order
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
return dataSource;
}
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
return properties;
}
@Bean
@Autowired
public HibernateTransactionManager transactionManager(SessionFactory s) {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(s);
return txManager;
}
My UI and View Class:
SuppressWarnings("serial")
@Theme("dashboardTheme")
@SpringUI()
public class DashboardUI extends UI {
@Autowired
private SpringViewProvider springViewProvider;
@Autowired
private PostValuesService postValuesService;
SampleSideBar sampleSideBar = new SampleSideBar();
LoginComponent loginComponent = new LoginComponent();
private TransMonitoring getTransGrid() throws ParseException {
Collection<PostValue> transList = postValuesService.getAllPostValues(null, null, null, null, null, null, null,
null, null, null, 100);
System.out.println(transList.size());
BeanItemContainer<PostValue> container = new BeanItemContainer<PostValue>(PostValue.class, transList);
return new TransMonitoring(container);
}
@Override
protected void init(VaadinRequest request) {
final VerticalLayout root = new VerticalLayout();
// root.setSizeFull();
root.setMargin(true);
root.setSpacing(true);
root.addComponent(loginComponent);
root.setComponentAlignment(loginComponent, Alignment.MIDDLE_CENTER);
setContent(root);
Navigator navigator = new Navigator(this, root);
navigator.addProvider(springViewProvider);
}
}
@SuppressWarnings("serial")
@UIScope
@SpringView(name = "")
public class LoginView extends VerticalLayout implements View {
public static final String VIEW_NAME = "";
@Autowired
private LoginService loginService;
@PostConstruct
void init() {
Button navBtn = new Button("Test");
navBtn.addClickListener(e -> getUI().getNavigator().navigateTo("dashboard"));
setSizeFull();
TextField textField = new TextField("UserName");
PasswordField passwordField = new PasswordField("Password");
Button loginBtn = new Button("Login");
Button cancelBtn = new Button("Cancel");
VerticalLayout layout = new VerticalLayout();
HorizontalLayout horizontalLayout = new HorizontalLayout();
// layout.setSizeFull();
horizontalLayout.addComponent(navBtn);
horizontalLayout.addComponent(loginBtn);
horizontalLayout.addComponent(cancelBtn);
layout.addComponent(textField);
layout.addComponent(passwordField);
layout.addComponent(horizontalLayout);
User user = loginService.getDetailsByUserName("h.sipalay");
loginBtn.addClickListener(e -> new Notification(user.toString()).show(Page.getCurrent()));
addComponent(layout);
}
@Override
public void enter(ViewChangeEvent event) {
// the view is constructed in the init() method()
}
}
It seems that it can't wire the SpringvVewpPovider. But then I also inluded the EnableVaadin annotation. Any ideas how can I solve this?
Thanks!
Hi Jethro,
DashboardUI should have @UIScope.
Ur LoginView should have ONLY @SpringView (not UIScope)!