This sample demonstrates a Spring Boot application that uses Spring Data JPA to access Db2 for z/OS data, deployed to a CICS Liberty JVM server. The application targets the employee sample table (EMP) supplied with Db2 for z/OS, and exposes REST endpoints to add, update, delete, and display employee records.
Key Features:
- Spring Data JPA: Uses Spring Boot's auto-configuration with Hibernate and Db2
- JNDI DataSource lookup: Connects to Db2 via a CICS type-2 JDBC connection configured in Liberty
- REST API: CRUD operations over the
EMPtable via simple HTTP GET endpoints - Jakarta EE 10: Spring Boot 3.x with
jakarta.*namespace andservlet-6.0 - Multi-build support: Gradle, Maven, and Eclipse (CICS Explorer SDK) deployment paths
- Overview
- Prerequisites
- Before You Start
- Reference
- Downloading
- Check Dependencies
- Building the Sample
- Deploying to a CICS Liberty JVM server
- Running the Sample
- Troubleshooting
- License
- Additional Resources
- Contributing
- CICS TS V6.1 or later (required for Spring Boot 3.x and Jakarta EE 10 support)
- A configured Liberty JVM server in CICS
- Java SE 17 or later on the workstation
- IBM Db2 V12 or later on z/OS with the CICS DB2CONN resource configured
- An Eclipse development environment on the workstation (optional)
- Either Gradle or Apache Maven on the workstation (optional if using Wrappers)
Before building and deploying this sample, you must customize the following files with your environment-specific values.
File: Liberty server.xml
Configure the IBM Data Server Driver for JDBC and SQLJ library and a type-2 DataSource:
<library id="db2Type2Driver">
<fileset dir="/usr/lpp/db2v12/jdbc/classes" includes="db2jcc4.jar db2jcc_license_cisuz.jar"/>
<fileset dir="/usr/lpp/db2v12/jdbc/lib" includes="libdb2jcct2zos4_64.so"/>
</library>
<dataSource id="db2Type2" jndiName="jdbc/jpaDataSource" transactional="false"
commitOrRollbackOnCleanup="commit" type="javax.sql.DataSource">
<jdbcDriver libraryRef="db2Type2Driver"/>
<properties.db2.jcc currentSchema="YOUR_SCHEMA" driverType="2"/>
<connectionManager agedTimeout="0"/>
</dataSource>Update the fileset dir paths to match your Db2 JDBC installation on z/OS, and set currentSchema to your Db2 schema name.
Before deploying, ensure your CICS region has:
- DB2CONN resource defined and installed in CICS
- CICS SIT parameter
DB2CONN=YES(required for JDBC Type 2 connections) - JCL — add these DD statements to your CICS region JCL to provide the Db2 load libraries:
// DD DSN=SYS2.DB2.V12.SDSNLOAD,DISP=SHR
// DD DSN=SYS2.DB2.V12.SDSNLOD2,DISP=SHRFile: Liberty server.xml
<featureManager>
<!-- Required for Spring Boot 3.x (Jakarta EE 10) -->
<feature>servlet-6.0</feature>
<!-- Required for JDBC DataSource -->
<feature>jdbc-4.3</feature>
</featureManager>Note:
servlet-6.0requires CICS TS V6.1 or later.cicsts:security-1.0is auto-injected by CICS when region security is active — do not add it manually. Forjdbc-4.3, ensuretype="javax.sql.DataSource"is set on the<dataSource>element when using a type-2 driver.
A complete template server.xml is provided in etc/config/liberty/server.xml.
More information about the development of this sample can be found in the blog Spring Boot Java applications for CICS, Part 4: Spring JPA
If using Eclipse: the simplest approach is to clone the repository using the Eclipse Git plugin (EGit) perspective.
If using the command line:
git clone https://github.com/cicsdev/cics-java-liberty-springboot-jpaAlternatively, download the sample as a ZIP and unzip onto the workstation.
If importing into Eclipse:
- In the Git Repositories view, right-click the repository → Import as Project (imports the root project) (if you cloned from the command line, use File → Import → Existing Projects into Workspace instead, browse to the cloned directory, select all projects, and skip to step 6)
- Switch to the Java EE perspective
- In the Project Explorer, right-click the
cics-java-liberty-springboot-jpa-appfolder → Import as Project - Right-click the
cics-java-liberty-springboot-jpa-cicsbundlefolder → Import as Project - Right-click the
cics-java-liberty-springboot-jpa-cicsbundle-eclipsefolder → Import as Project - Required: Right-click the root project → Gradle → Refresh Gradle Project or Maven → Update Project... — this resolves Spring Boot and CICS dependencies into the project classpath. Without this step, the WTP export will produce an incomplete WAR missing
WEB-INF/lib.
Before building this sample, you should verify the correct CICS TS bill of materials (BOM) version for your CICS release. The BOM specifies a consistent set of artifacts and their scopes. You can browse the published versions of the CICS BOM at Maven Central.
This sample uses Spring Data JPA and does not require JCICS directly. No BOM entry is required for the JPA sample.
You can build the sample using an IDE of your choice, or you can build it from the command line. For both approaches, using the supplied Gradle or Maven wrapper is the recommended way to get a consistent version of build tooling.
On the command line, you simply swap the Gradle or Maven command for the wrapper equivalent, gradlew or mvnw respectively.
For an IDE, taking Eclipse as an example, the plug-ins for Gradle buildship and Maven m2e will integrate with the "Run As..." capability, allowing you to specify whether you want to build the project with a Wrapper, or a specific version of your chosen build tool.
The required build-tasks are clean build for Gradle and clean verify for Maven. Once run, Gradle will generate a WAR file in the cics-java-liberty-springboot-jpa-app/build/libs directory, while Maven will generate it in the cics-java-liberty-springboot-jpa-app/target directory.
Note: When building a WAR file for deployment to Liberty it is good practice to exclude Tomcat from the final runtime artifact. We demonstrate this in the pom.xml with the provided scope, and in build.gradle with the providedRuntime() dependency.
Run the following in a local command prompt:
On Linux or Mac:
./gradlew clean buildOn Windows:
gradlew.bat clean buildThis creates a WAR file inside the cics-java-liberty-springboot-jpa-app/build/libs directory.
Note: In Eclipse, the
builddirectory may be hidden by default. To view it: Package Explorer → ⋮ → Filters and Customization → uncheck "Gradle build folder". For Maven, thetargetdirectory is visible by default.
Run the following in a local command prompt:
On Linux or Mac:
./mvnw clean verifyOn Windows:
mvnw.cmd clean verifyThis creates a WAR file inside the cics-java-liberty-springboot-jpa-app/target directory.
Ensure your Liberty server.xml and CICS region are configured as described in Before You Start. A complete template server.xml is provided in etc/config/liberty/server.xml.
The src/main/resources/application.properties file contains:
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.DB2Dialect
spring.jpa.show-sql=true
spring.data.jpa.repositories.bootstrap-mode=defaultspring.jpa.show-sqlis optional but useful to display the SQL generated by Hibernate.spring.jpa.properties.hibernate.dialectensures Hibernate generates Db2-compatible SQL.spring.data.jpa.repositories.bootstrap-mode=defaultis required — do NOT usedeferredorlazyas these attempt asynchronous database access on a non-CICS/Db2-enabled thread.
This method uses the cics-bundle-gradle-plugin or cics-bundle-maven-plugin to automatically generate a CICS bundle.
Configure your JVM server name:
Gradle (cics-java-liberty-springboot-jpa-cicsbundle/build.gradle):
cics.jvmserver = 'YOUR_JVMSERVER_NAME' // e.g., 'DFHWLP'Maven (cics-java-liberty-springboot-jpa-cicsbundle/pom.xml):
<cics.jvmserver>YOUR_JVMSERVER_NAME</cics.jvmserver> <!-- e.g., DFHWLP -->Deploy the bundle:
-
Upload the CICS bundle ZIP file to zFS:
- Gradle:
cics-java-liberty-springboot-jpa-cicsbundle/build/distributions/cics-java-liberty-springboot-jpa-cicsbundle-1.0.0.zip - Maven:
cics-java-liberty-springboot-jpa-cicsbundle/target/cics-java-liberty-springboot-jpa-cicsbundle-1.0.0.zip
- Gradle:
-
Unzip the bundle on zFS
-
Create a CICS BUNDLE resource definition:
CEDA DEFINE BUNDLE(JPA) GROUP(MYGROUP) BUNDLEDIR(/path/to/bundle) -
Install the bundle:
CEDA INSTALL BUNDLE(JPA) GROUP(MYGROUP)
Alternative: Use the CICS deployment API via CMCI to deploy the bundle remotely.
This repository includes a pre-configured Eclipse CICS bundle project cics-java-liberty-springboot-jpa-cicsbundle-eclipse that can be used directly with CICS Explorer SDK.
- Right-click the
cics-java-liberty-springboot-jpa-cicsbundle-eclipseproject → Export Bundle Project to z/OS UNIX File System and follow the wizard
Note: The bundle project is pre-configured so that the Eclipse WTP export automatically packages the application WAR with all dependencies. This relies on the
-appproject being open in the same Eclipse workspace. If you have not yet imported the project, follow steps 3 and 6 of the Importing into Eclipse instructions first.
- Manually upload the WAR file to zFS
- Add an
<application>element to the Liberty server.xml to define the web application with access to all authenticated users. For example:
<application id="cics-java-liberty-springboot-jpa"
location="${server.config.dir}/springapps/cics-java-liberty-springboot-jpa.war"
name="cics-java-liberty-springboot-jpa" type="war">
<application-bnd>
<security-role name="cicsAllAuthenticated">
<special-subject type="ALL_AUTHENTICATED_USERS"/>
</security-role>
</application-bnd>
</application>-
Ensure the web application started successfully in Liberty by checking for msg
CWWKT0016Iin the Liberty messages.log:CWWKT0016I: Web application available (default_host): http://myzos.mycompany.com:httpPort/cics-java-liberty-springboot-jpa -
Visit the root URL from a browser:
http://myzos.mycompany.com:httpPort/cics-java-liberty-springboot-jpa/The browser will prompt for basic authentication. Enter a valid userid and password for your Liberty JVM server.
-
Available endpoints:
GET /allEmployees— returns all rows from theEMPtableGET /listEmployee/{empno}— returns the employee with the given employee numberGET /addEmployee/{firstName}/{lastName}— adds a new employee recordGET /updateEmployee/{empNo}/{newSalary}— updates the salary for an employeeGET /deleteEmployee/{empNo}— deletes the employee with the given number
Example:
http://myzos.mycompany.com:httpPort/cics-java-liberty-springboot-jpa/allEmployees
Application fails to start — CWWKZ0013E or SRVE0190E
- Verify
servlet-6.0is enabled in your Libertyserver.xml. - Confirm CICS TS V6.1 or later is installed — earlier releases do not support Jakarta EE 10.
ClassNotFoundException for jakarta.persistence.*
- This sample uses
jakarta.*namespace (Spring Boot 3.x / Jakarta EE 10). Ensure you are not running against a CICS TS release older than V6.1, which usesjavax.*.
HibernateException or DataSource lookup failure
- Verify the
<dataSource>JNDI name inserver.xmlisjdbc/jpaDataSource. - Confirm a CICS DB2CONN resource is active and the region has access to Db2.
- Check
spring.jpa.properties.hibernate.dialectis set correctly inapplication.properties.
Empty result set / SQL errors
- Confirm the Db2 schema name in
<properties.db2.jcc currentSchema="..."/>matches your Db2 installation. - Verify the
EMPtable exists in the configured schema.
This project is licensed under Eclipse Public License - v 2.0.
- CICS TS Documentation
- WebSphere Liberty Documentation
- Spring Boot Documentation
- Spring Data JPA Documentation
- Spring Boot Java applications for CICS, Part 4: Spring JPA
This sample is maintained by IBM CICS development. We welcome bug reports and feature requests via GitHub Issues. Contributions are welcome and reviewed on a case-by-case basis — please read the contributing guidelines before opening a pull request. For CICS product questions, contact IBM Support.