TM1 Spring Boot starter · Walkthrough 1 of 1
Add TM1 to a Spring Boot application
You add TM1 to a Spring Boot application. The starter builds a TM1 client from your settings, and you inject it where you need it.
Before you start
- A Spring Boot 4 application. start.spring.io makes one.
- A TM1 server. Run Planning Analytics on your own computer starts one on
http://localhost:8010, with the loginadminand no password. You need your own licensed copy of TM1 Server.
Steps
Add the starter.
Needs Java 17 or later.
Gradle (Kotlin)
implementation("io.skipcheck:tm1-spring-boot-starter:0.1.1")Maven
<dependency> <groupId>io.skipcheck</groupId> <artifactId>tm1-spring-boot-starter</artifactId> <version>0.1.1</version> </dependency>Tell it where TM1 is. Put the server's address and your login in
application.yml:application.yml # src/main/resources/application.yml tm1: # Where TM1 is: the server's address, as for tm1-server on this computer address: http://localhost:8010 # Who to log in as: tm1-server's default admin, with no password user: admin password: "" # With Cognos (CAM) security, also name the CAM namespace: # namespace: LDAPKeep a real password out of the file: Spring Boot can fill the setting from an environment variable, with a property placeholder. Tm1Properties lists every setting.
Use the client. The starter makes a
Tm1Clientbean. This application asks for it, and prints the server's version and its cubes when it starts. The server set up above has an empty database, so it has no cubes yet:Java import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import io.skipcheck.tm1.client.Tm1Client; import io.skipcheck.tm1.client.model.Cube; import io.skipcheck.tm1.client.odata.ODataQuery; @SpringBootApplication public class HelloTm1Application { public static void main(String[] args) { SpringApplication.run(HelloTm1Application.class, args); } // The starter built the client from the tm1 settings: just ask for it @Bean ApplicationRunner hello(Tm1Client tm1) { return args -> tm1.session() .version() .doOnNext(version -> System.out.println("Hello from TM1 " + version)) .thenMany(tm1.cubes().modelCubes(ODataQuery.none().select(Cube.NAME))) .doOnNext(cube -> System.out.println(" " + cube.name())) .then() .block(); // fine at startup; in a web request, return the Flux instead } }Output Hello from TM1 11.8.03500.6Run it with
./gradlew bootRun(ormvn spring-boot:run).Inject it into your own beans. Ask for
Tm1Clientin a constructor. Its calls returnMonoandFlux, which Spring WebFlux returns as they are; in Spring MVC, block for the result.Java // Its settings are tm1.address, tm1.user and tm1.password, in application.yml @Service static class SalesCubes { private final Tm1Client tm1; SalesCubes(Tm1Client tm1) { this.tm1 = tm1; } Flux<String> names() { return tm1.cubes().modelCubes(ODataQuery.none().select(Cube.NAME)).map(Cube::name); } }
Next
- A session per user, from a pool: the beans the starter makes.
- Several servers, each by its name.
- A real TM1 in your Spring Boot tests: tm1-spring-boot-testcontainers.