Skip to content

Latest commit

 

History

History
94 lines (70 loc) · 6.4 KB

File metadata and controls

94 lines (70 loc) · 6.4 KB
synopsis This section shows how CAP Java is smoothly integrated with Spring Boot.
status released

Spring Boot Integration

<style scoped> h1:before { content: "Java"; display: block; font-size: 60%; margin: 0 0 .2em; } </style>

{{ $frontmatter.synopsis }}

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:

<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:

<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 { #exposed-beans}

Bean Description Example
Service All kinds of CDS services, application services, and technical services @Autowired
CatalogService catService;

@Autowired
CatalogService.Draft catServiceDraft;

@Autowired
PersistenceService ps;
ServiceCatalog The catalog of all available services @Autowired
ServiceCatalog catalog;
CdsRuntime Runtime instance (singleton) @Autowired
CdsRuntime runtime;
CdsRuntimeConfigurer Runtime configuration instance (singleton) @Autowired
CdsRuntimeConfigurer configurer;
CdsModel The current model @Autowired
CdsModel model;
UserInfo Information about the authenticated user @Autowired
UserInfo userInfo;
AuthenticationInfo Authentication claims @Autowired
AuthenticationInfo authInfo;
ParameterInfo Information about request parameters @Autowired
ParameterInfo paramInfo;
Messages Interface to write messages @Autowired
Messages messages;
FeatureTogglesInfo Information about feature toggles @Autowired
FeatureTogglesInfo ftsInfo;
CdsDataStore Direct access to the default data store @Autowired
CdsDataStore ds;