Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.miwurster:spring-data-influxdb:spring-data-influxdb-1.8'
}
dependencies {
implementation("com.github.miwurster:spring-data-influxdb:spring-data-influxdb-1.8")
}
<dependency>
<groupId>com.github.miwurster</groupId>
<artifactId>spring-data-influxdb</artifactId>
<version>spring-data-influxdb-1.8</version>
</dependency>
libraryDependencies += "com.github.miwurster" % "spring-data-influxdb" % "spring-data-influxdb-1.8"
:dependencies [[com.github.miwurster/spring-data-influxdb "spring-data-influxdb-1.8"]]
The primary goal of the Spring Data project is to make it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services.
This modules provides integration with the InfluxDB database and wraps the capabilities of the official influxdb-java library.
<dependency>
<groupId>com.github.miwurster</groupId>
<artifactId>spring-data-influxdb</artifactId>
<version>1.8</version>
</dependency>
Following properties can be used in your application.yml
:
spring:
influxdb:
url: http://localhost:8086
username: user
password: ~
database: test
retention-policy: autogen
Optionally, you can also configure connections, read, and write timeouts (in seconds):
spring:
influxdb:
connect-timeout: 10
read-timeout: 30
write-timeout: 10
Furthermore, one can enable gzip compression in order to reduce size of the transferred data:
spring:
influxdb:
gzip: true
Create InfluxDBConnectionFactory
and InfluxDBTemplate
beans:
@Configuration
@EnableConfigurationProperties(InfluxDBProperties.class)
public class InfluxDBConfiguration
{
@Bean
public InfluxDBConnectionFactory connectionFactory(final InfluxDBProperties properties)
{
return new InfluxDBConnectionFactory(properties);
}
@Bean
public InfluxDBTemplate<Point> influxDBTemplate(final InfluxDBConnectionFactory connectionFactory)
{
/*
* You can use your own 'PointCollectionConverter' implementation, e.g. in case
* you want to use your own custom measurement object.
*/
return new InfluxDBTemplate<>(connectionFactory, new PointConverter());
}
@Bean
public DefaultInfluxDBTemplate defaultTemplate(final InfluxDBConnectionFactory connectionFactory)
{
/*
* If you are just dealing with Point objects from 'influxdb-java' you could
* also use an instance of class DefaultInfluxDBTemplate.
*/
return new DefaultInfluxDBTemplate(connectionFactory);
}
}
Use InfluxDBTemplate
to interact with the InfluxDB database:
@Autowired
private InfluxDBTemplate<Point> influxDBTemplate;
influxDBTemplate.createDatabase();
final Point p = Point.measurement("disk")
.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
.tag("tenant", "default")
.addField("used", 80L)
.addField("free", 1L)
.build();
influxDBTemplate.write(p);
Spring Data InfluxDB uses Maven as its build system.
mvn clean install