skipcheck

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.

  1. 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>
  2. 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: LDAP

    Keep 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.

  3. Use the client. The starter makes a Tm1Client bean. 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.6

    Run it with ./gradlew bootRun (or mvn spring-boot:run).

  4. Inject it into your own beans. Ask for Tm1Client in a constructor. Its calls return Mono and Flux, 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);
        }
    
    }