How to integrate Vaadin with Spring without spring Boot

[code]
@SpringUI
@Theme(“mytheme”)
public class MyUI extends UI {

@Autowired
private Hello hello;

@Override
protected void init(VaadinRequest vaadinRequest) {
    setContent(new Label(hello.sayHello()));      
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet  {
}

}
[/code]I have tried examples of vaadin spring integration, but nothing works fine. I tried SpringBoot with vaadin its working. but I need only spring. I attached MyUI and Normal Class, Plaese Have a look.[code]
@UIScope
@Configuration
@EnableVaadin
public class Hello {

@Bean
public  String sayHello() {
    return "Hello from bean ";
}

}
[/code]I am getting
java.lang.NullPointerException. Am I missing anything?

MyUIServlet needs to extend SpringVaadinServlet instead of VaadinServlet. Let me know, if that helped.
The spring tutorial has a section for getting started without boot:
http://vaadin.github.io/spring-tutorial/#getting-started-no-boot

I changed to SpringVaadinServlet, now I am getting “No UIProvider has been added and there is no “UI” init parameter.” this error.

You need the applicationContext.xml and ContextLoaderListener too. Matti has a sample in his GitHub. I didn’t test, but I trust it works:
https://github.com/mstahv/vaadin-spring-noboot/blob/master/src/main/java/org/test/MyUI.java

Thankyou! Its working fine.

Hayry, can u please send me the link of vaadinSpring CRUD example without boot.I searched for it but I found boot examples only.

I know there must be, but I didn’t find anything now. Which part of these crud tutorials is problematic for you to implement without boot?

Actually I am new to Spring vaadin integration. I tried this example
https://spring.io/guides/gs/crud-with-vaadin/
. It is in spring boot and working. I removed boot part and used Xml file and application context to get that Xml. Normally in boot we run the main class and then piont to the localhost. But what about in spring, what is the process? Do I need Xml Main class and which class should I run? Its little bit confusing.
When I run UI class error is “BeanFactory not initialized or already closed - call ‘refresh’ before accessing beans via the ApplicationContext”.
Here is my xml and main class where boot part is there. I replaced it with followin code.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <jpa:repositories base-package="com.hellorepo" />

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
      <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.hello" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="database" value="HSQL" />
                <property name="generateDdl" value="true" />                
            </bean>
        </property>
    </bean>
    
    <jdbc:embedded-database id="dataSource" type="HSQL" />

    <context:annotation-config />
    <bean id="mainBean"
        class="com.hello.Application" />

</beans>
@ComponentScan
@EnableAutoConfiguration

public class Application {
    @Autowired
    private CustomerRepository repository;
    
    public static void main(String[] args) throws IOException{
        //SpringApplication.run(Application.class,args);
        
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicaton.xml");
        try{
             Application app = (Application) ctx.getBean("mainBean",Application.class);
             System.out.println("Employess");
           app.addCustomer();
        } finally {
            ctx.close();
        }
        }
    
    private void addCustomer() {
       
        repository.save(new Customer("Chloe", "O'Brian"));
       repository.save(new Customer("Kim", "Bauer"));
        repository.save(new Customer("David", "Palmer"));
        repository.save(new Customer("Michelle", "Dessler"));
        repository.findAll().forEach(System.out::println);
}}

Well classical Spring is usually built as a WAR and then deployed to some servlet container. Although, you can build spring-boot project as a WAR too. Out of curiosity, which part of the spring-boot makes it uncomfortable for you to be used?

I modified Matti’s sample to contain spring data and hibernate and stuff. It’s built as war. mvn package jetty:run to test it.

https://github.com/johannesh2/vaadin-spring-noboot

We are already working with vaadin and jpa container, due to some performance issues we tought to shift to vaadin spring without boot. If we use boot we may need to change a lot of code in existing project.
And I din’t find anything in this link
https://github.com/johannesh2/vaadin-spring-noboot
.

Okay I though you asked Spring data crud sample without Spring boot. Sorry if I understood incorrectly or my implementation wasn’t helpful.

Hey,Its ok. But I need Vaadin Spring Integration CRUD example. Plaese,Help me if you find any link for that.

In the project I linked I had copied the code from https://github.com/spring-guides/gs-crud-with-vaadin and implemented that without boot. Only thing it is missing is jar packaging and the main method loading test data into database. Is that main method the crucial part or what part you are missing from the crud integration?

Thank you so much Hayry. The project you posted is working well.

Johannes Häyry:
You need the applicationContext.xml and ContextLoaderListener too. Matti has a sample in his GitHub. I didn’t test, but I trust it works: https://github.com/mstahv/vaadin-spring-noboot/blob/master/src/main/java/org/test/MyUI.java

if we don’t need applicationContext.xml and ContextLoaderListener as I’ve java configuration then what should i do?