Spring Boot Integration | capire

This section shows how CAP Java is smoothly integrated with Spring Boot.

This section describes the Spring Boot integration of the CAP Java SDK. Classic Spring isn't supported. Running your application with Spring Boot framework offers a number of helpful benefits that simplify the development and maintenance of the application to a high extend. Spring not only provides a rich set of libraries and tools for most common challenges in development, you also profit from a huge community, which constantly contributes optimizations, bug fixes and new features.

As Spring Boot is not only widely accepted but also the most popular application framework, CAP Java SDK comes with seamless integration of Spring Boot as described in the following sections.

Integration Configuration

To make your web application ready for Spring Boot, you need to make sure that the following Spring dependencies are referenced in your pom.xml (group ID org.springframework.boot):

  • spring-boot-starter-web
  • spring-boot-starter-jdbc
  • spring-boot-starter-security (optional)

In addition, for activating the Spring integration of CAP Java, the following runtime dependency is required:

xml

<dependency>
	<groupId>com.sap.cds</groupId>
	<artifactId>cds-framework-spring-boot</artifactId>
	<version>${cds.services.version}</version>
	<scope>runtime</scope>
</dependency>

It might be easier to use the CDS starter bundle cds-starter-spring-boot-odata, which not only comprises the necessary Spring dependencies, but also configures the OData V4 protocol adapter:

xml

<dependency>
	<groupId>com.sap.cds</groupId>
	<artifactId>cds-starter-spring-boot-odata</artifactId>
	<version>${cds.services.version}</version>
</dependency>

Tip

If you refrain from adding explicit Spring or Spring Boot dependencies in your service configuration, the CDS integration libraries transitively retrieve the recommended Spring Boot version for the current CAP Java version.

Integration Features

Besides common Spring features such as dependency injection and a sophisticated test framework, the following features are available in Spring CAP applications:

  • CDS event handlers within custom Spring beans are automatically registered at startup.
  • Full integration into Spring transaction management (@Transactional is supported).
  • A number of CAP Java SDK interfaces are exposed as Spring beans and are available in the Spring application context such as technical services, the CdsModel, or the UserInfo in current request scope.
  • Automatic configuration of XSUAA, IAS, and mock user authentication by means of Spring security configuration.
  • Integration of cds-property section into Spring properties. See section Externalized Configuration in the Spring Boot documentation for more details.
  • The cds actuator exposing monitoring information about CDS runtime and security.
  • The DB health check indicator which also applies to tenant-aware DB connections.

Tip

None of the listed features will be available out of the box in case you choose to pack and deploy your web application as plain Java Servlet in a war file.

CDS Spring Beans

BeanDescriptionExample
ServiceAll kinds of CDS services, application services, and technical services@Autowired
CatalogService catService;

@Autowired
CatalogService.Draft catServiceDraft;

@Autowired
PersistenceService ps;

ServiceCatalogThe catalog of all available services@Autowired
ServiceCatalog catalog;
CdsRuntimeRuntime instance (singleton)@Autowired
CdsRuntime runtime;
CdsRuntimeConfigurerRuntime configuration instance (singleton)@Autowired
CdsRuntimeConfigurer configurer;
CdsModelThe current model@Autowired
CdsModel model;
UserInfoInformation about the authenticated user@Autowired
UserInfo userInfo;
AuthenticationInfoAuthentication claims@Autowired
AuthenticationInfo authInfo;
ParameterInfoInformation about request parameters@Autowired
ParameterInfo paramInfo;
MessagesInterface to write messages@Autowired
Messages messages;
FeatureTogglesInfoInformation about feature toggles@Autowired
FeatureTogglesInfo ftsInfo;
CdsDataStoreDirect access to the default data store@Autowired
CdsDataStore ds;