openxava / documentation / Spring Boot

Spring Boot is a tool that makes web application and microservices development with Spring Framework faster and easier.
The idea of integrating OpenXava into a simple Spring Boot application with Rest services and JPA is to leverage the automatically generated view by OpenXava. We will work with our sample project and import it into Spring Tool Suite 4 for Eclipse. You will also need OpenXava Studio and MySQL (we will use MySQL 8 in this example). Finally, we will deploy the application on a Tomcat 9 server.

Import and configure the project in Spring Tool Suite 4

Download the project as a zip file then unzip it.

Select Import projects from Package Explorer view or File > Import and select Existing Maven Projects.

Browse to the folder where you unzipped the project and select it.

Open the file located in src/main/resources and adapt it to your MySQL database by providing URL, username, password, and dialect. Make sure your MySQL database is up and running.

Manually create some records in your MySQL database:

INSERT INTO `yourdatabase`.`tutorials` (`id`, `description`, `published`, `title`) 
VALUES ('1', 'description 1', 0, 'title 1');

Verify that the services are working correctly http://localhost:8080/api/tutorials

Create and configure project in OpenXava

What we need to do now is copy the configuration files generated by OpenXava when a new project is created to Spring Boot project, so the project must have the same configurations as the Spring Boot project.

Create a new OpenXava project using OpenXava Studio.


Project name: openxava-spring-boot-example

Group id: com.example

Add the MySQL8 dialect in the persistence.xml file located in src/main/resources/META-INF.

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect"/>

Configure the context.xml file in the src/main/webapp/META-INF folder. Comment out the HSQLDB resource and use the MySQL resource instead. Configure the database connection using your URL, username, and password.

Replace and copy files to the Spring Boot project

Now, let's go back to the project in Spring Tool Suite 4 and proceed to integrate OpenXava into a Spring Boot application. There are several ways to do this, and we will use one of them. First, you need to replace the file and configure it manually by creating a @Configuration class.
To do this, create a class named AppConfig in the com.example.openxava.spring.boot.example package. Inside the dataSource() method, define the database connection configurations (URL, username, password), entities, and repositories to be scanned, for example:
package com.example.openxava.spring.boot.example;

import java.util.Properties;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;

public class AppConfig {

    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        return dataSource;

    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        return entityManagerFactory;

    private Properties hibernateProperties() {
        Properties properties = new Properties();
        properties.setProperty("", "update");
        properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL8Dialect");
        return properties;

Remove the file and ensure that the services continue to function correctly by accessing  http://localhost:8080/api/tutorials
Add extends SpringBootServletInitializer in the OpenxavaSpringBootExampleApplication class located in the com.example.openxava.spring.boot.example package.
public class OpenxavaSpringBootExampleApplication extends SpringBootServletInitializer {

	public static void main(String[] args) throws Exception {, args);

Now, configure the pom.xml file by adding packaging war, OpenXava dependency (you can use the latest available version, from 7.1.1). The finalName is optional, but we will use it in this example.

<dependencies> ... <dependency> <groupId>org.openxava</groupId> <artifactId>openxava</artifactId> <version>7.1.1</version> </dependency> </dependencies>

<build> <finalName>openxavaspringbootexample</finalName> </build>
Finally, copy the following files and folders from the OpenXava project to the Spring Boot project under the same path:

Your project should now have these changes implemented.

Run application

Before running the application, make sure to set up JAVA_HOME and perform the following steps:

Copy the openxavaspringbootexample.war file from the target folder to the webapp folder of your installed Tomcat 9. Then, run startup.bat from the bin folder.

Open your browser and access the following URL to open the OpenXava application (login with admin/admin if you haven't done the optional step):

To take advantage of the views generated by OpenXava with the project entities, you can now perform CRUD operations.

Verify that the Spring Boot project services are working by accessing: http://localhost:8080/openxavaspringbootexample/api/tutorials

You will notice that instead of returning JSON, it is returning XML. This is due to a bug in the JasperReports library that comes with OpenXava. We will temporarily resolve this issue in this example by excluding a dependency from that library. However, it is not recommended to do this in a production environment.


If you want to remove "openxavaspringbootexample" from the URL, simply rename the  springbootdatajpa.war file to ROOT.war in the webapps folder. With this change, you can access the OpenXava application using http://localhost:8080 and the services as before using http://localhost:8080/api/tutorials