Fire_Phoenix_1.jpg

It happens quite often that you quickly want to get something running with OpenUI5 and OData, quickly smack it on a web-server or cloud instance, but just don’t look forward building the project completely start from scratch. Think hackathons, in which time is very limited already… That’s when an OpenUI5 boilerplate would come in handy.


That’s why I have compiled a relatively small application that connects to a database (mysql by default), builds to a jar, allows you to model your data using JPA (and the JPA diagram editor), exposes the model through OData and has a tiny OpenUI5 application that uses the OData and shows the content of the database.


For convenience, a base-diagram for the JPA diagram editor has been provided as well. Once the datamodel is finished, the application with update the data model of the connected database on first run.


By default, the application comes with just one entity: Members, that is automatically populated with a few names from Application.java


Once the application is running, you can browse to http://localhost:8080 to run the sample OpenUI5 application that is using the OData service. The service itself is available from http://localhost:8080/odata.svc.


The only thing you need for this, is a local install of Maven and Java 1.8, once you have that just clone the github repository to your computer:


git clone https://github.com/jpenninkhof/odata-boilerplate.git


Modify file “/src/main/resources/application.properties” to connect to your own database.


And run it:

mvn spring-boot:run


On first run, the application will introspect the database that it has been connected to, and will make sure the database is in sync with it’s internal model. If necessary tables will be created or altered.


And with that, you’re ready to run the OpenUI sample app from http://localhost:8080/openui5-boilerplate

/wp-content/uploads/2016/02/openui5_boilerplate_891965.png

Contributions are welcome. Just fork it and submit a pull request.


Related links:


To report this post you need to login first.

9 Comments

You must be Logged on to comment or reply to a post.

  1. Mathias Maerker

    Very nice indeed! Could you maybe provide an example with eclipselink and local embedded derby database? I am struggling a little here 😉

    Regards

    Mathias

    (0) 
  2. Guillaume DES POMMARE

    Hello Jan,

    I did not invest so much time (yet) but I found very interesting to get a quick start project having odata/springboot and ui5 ready to be used. Very nice and clever idea.

    I did a clone and followed your instructions but I already face a spring issue. As the error is located deep into spring layers, I have no idea what is happening here. But maybe you will have some ideas.

    The error is (after doing a ‘clean install’ then a ‘spring-boot:run’):

      .   ____          _            __ _ _

    /\\ / ___’_ __ _ _(_)_ __  __ _ \ \ \ \

    ( ( )\___ | ‘_ | ‘_| | ‘_ \/ _` | \ \ \ \

    \\/  ___)| |_)| | | | | || (_| |  ) ) ) )

      ‘  |____| .__|_| |_|_| |_\__, | / / / /

    =========|_|==============|___/=/_/_/_/

    :: Spring Boot ::        (v1.3.2.RELEASE)

    [WARNING]

    java.lang.reflect.InvocationTargetException

            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

            at java.lang.reflect.Method.invoke(Method.java:497)

            at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:478)

            at java.lang.Thread.run(Thread.java:745)

    Caused by: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

            at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)

            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)

            at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)

            at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)

            at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)

            at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)

            at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)

            at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)

            at com.penninkhof.odata.Application.main(Application.java:21)

            … 6 more

    Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

            at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:185)

            at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158)

            at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130)

            … 14 more

    In case you can double check if your project still works, or is now broken due to some updates in spring boot.

    Thanks 🙂

    Guillaume

    (0) 
    1. Jan Penninkhof

      Hi Guillaume, Could it be that you didn’t pick Tomcat as your runtime?

      If you didn’t, could you try running it on a “Java Web Tomcat 7” runtime instead?

      Cheers,

      Jan

      (0) 
      1. Guillaume DES POMMARE

        I can try again, using eclipse.

        But I was only launching using the command line (‘mvn spring-boot:run’ or ‘mvn spring-boot:run -P jar’) and I don’t think there that you need any runtime defined.

        I will let you know in case defining a runtime helps.

        Regards,
        Guillaume

        (0) 
        1. Jan Penninkhof

          Ah, gotcha!

          If you’re running it directly using `mvn spring-boot:run -P jar`, you have to make sure that you have made the application.properties file point to a valid database. You could e.g. comment the HCP DB settings in that file and uncomment HSQLDB.

          If you link the app to a HSQLDB database, you need to add a HSQLDB driver to the pom.xml as well. I have also modified the github repo a bit so that HSQLDB is automatically included, so you can choose to manually modify the pom.xml, or pull the latest version from the git repo.


          In short:

          1. git clone https://github.com/jpenninkhof/odata-boilerplate.git

          2. Modify application.properties (comment HCP DB portion, uncomment HSQLDB portion)

          3. Run `mvn spring-boot:run -P jar`

          4. Point your browser at http://localhost:8080

          Cheers,

          Jan

          (0) 

Leave a Reply