Home / Integration / Spring Boot and WordPress CMS Integration

Spring Boot and WordPress CMS Integration

There are a lot of excellent open source content management systems available today,  WordPress being one of them, which is widely used. WordPress is a PHP based CMS so not a lot of cohesion is available with other technologies like Java, and is simply ignored as a viable content management option just for being non-Java.

In this post I will demonstrate how WordPress can be integrated with Spring Boot applications, all made possible with WordPress REST plugin and a Spring client. Both of these are open source and available for free. Below is a simple design diagram that explains how this integration works. This post assumes that the reader has prior knowledge of WordPress and Spring Boot.


spring-wpapi-simple
First install and activate WP-API v2 plugin on the WordPress site. After activation, you could verify that the plugin is working by accessing http://yoursite/wp-json/wp/v2/posts, which should display all the posts in JSON format.

In the spring boot application add the following dependency in order to include the Spring WP-API client.

Below is a sample configuration we need in the application.properties file, so that we can connect our Spring Boot application to our WordPress site.




The Spring WP-API client needs the RestTemplate so lets create a bean in our Application and autowire the Spring client. We also need to add component scan annotation so that Spring finds and autowires all the required dependencies.

Now our spring boot application is all setup to connect to out WordPress site in order to retrieve and create content. So lets try and lookup all the posts having the keyword “Spring”, below is how we can do this.

The complete test application is available with the Spring WP-API client on Github.

This is just a small example of how we can integrate Spring Boot and WordPress. We can take this further by properly integrating WordPress in the Spring web applications platform, e.g. by enabling Single Sign On using the CAS plugin.


spring-wpapi-cas
And we can evolve this design even further by having a second-level content storage, like a database or an in-memory caching solution etc. This storage can serve as a cache and can also be used for additional configuration, so that we display relevant content faster in our Spring applications.


spring-wpapi-cas-db
For more information please see the documentation of the WordPress REST plugin and Spring WP-API client.

About Author:

One thought on “Spring Boot and WordPress CMS Integration

  1. Hi Kamran,

    Thank you for this article and sources’s project. Very helpull and usefull.
    I’ve installed plugins in wordpress :
    – WP REST API (to accept rest call)
    – VA Simple Basic Auth
    – WP OAuth Server
    But, i still have 403 response (access denied)
    What’s type of authentification do you use ?
    How can i set it correctly in wordpress ? is it a problem of .htaccess ?
    How can i log the requests in the project ?
    Thank for your response.

Leave A Comment

Your email address will not be published. Required fields are marked *