Higson Runtime Spring Boot Starter

Prerequisites#

  • Java 17
  • Maven 3.x
  • Spring Boot 3

Maven Configuration#

Apart from standard Spring Boot dependencies, you need to include spring-boot-starter-higson-runtime dependency, available in Maven Central. Add spring-boot-starter-higson-runtime dependency to pom.xml file:

1
2
3
4
5
6

<dependency>
	<groupId>io.higson</groupId>
	<artifactId>spring-boot-starter-higson-runtime</artifactId>
	<version>${higson-runtime.version}</version>
</dependency>

Another needed dependency is the JDBC driver to the database of choice, e.g., h2, oracle, mssql, postgresql:

1
2
3
4
5
6

<dependency>
	<groupId>com.h2database</groupId>
	<artifactId>h2</artifactId>
	<version>${h2-database.version}</version>
</dependency>

Properties#

With the above setup, all the configuration that is needed is application.yml file with database properties:

1
2
3
4
5
higson:
  database:
    username: <username>
    password: <password>
    url: <jdbc_url>

If required properties are not available, spring-boot-starter-higson-runtime will return an adequate message.

To configure external sources, you have to set comma separated list of external sources names and connection properties for each of them. You can do it by using the properties below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
higson:
  runtime:
    external-datasource:
      sql:
        names: postgres,h2
        postgres:
          url: <postgres_jdbc_url>
          password: <postgres_password>
          username: <postgres_username>
        h2:
          url: <h2_jdbc_url>
          username: <h2_username>
          password: <h2_password>

Using Auto-Configured HigsonEngine#

After successfully configuring properties while starting the application, spring will create HigsonEngine bean available in the spring application context, then which can be injected anywhere:

1
2
3
4
5
6
7
@Component
public class HigsonClient {

	@Autowired
	private HigsonEngine engine;

}

Overriding Default Configuration#

To override default auto-configuration, you need to define HigsonEngine bean in the @Configuration class:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
@Configuration
class CustomHigsonConfiguration {

	@Bean
	public HigsonEngine higsonEngine() {
		var factory = new HigsonEngineFactory();
		return factory.create();
	}

}

Existing auto-configured DataSource and HigsonRuntimeProperties can be used simply by injecting them:

1
2
3
4
5
public class HigsonEngine(
	HigsonRuntimeProperties properties,
	@Qualifier("higsonDataSource") DataSource dataSource
) {
}

Disabling Higson#

If you want to disable higson temporarily for some reason, you can do it with property higson.runtime.enabled set to false.

1
2
3
higson:
  runtime:
    enabled: false