Skip to content

Commit 399170e

Browse files
committed
Add autoconfiguration and starter for Spring Boot 3
1 parent 1392c5e commit 399170e

File tree

9 files changed

+214
-3
lines changed

9 files changed

+214
-3
lines changed

api-client-spring-boot-2-autoconfigure/src/main/java/com/recombee/api_client/spring/boot/_2/autoconfiguration/RecombeeClientAutoconfiguration.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ RecombeeClientProperties recombeeClientProperties() {
2626
@Bean
2727
@ConditionalOnMissingBean
2828
RecombeeClient recombeeClient(RecombeeClientProperties recombeeClientProperties) {
29-
return new RecombeeClient(recombeeClientProperties.getDatabaseId(),
30-
recombeeClientProperties.getToken()).setRegion(recombeeClientProperties.getRegion());
29+
return new RecombeeClient(recombeeClientProperties.getDatabaseId(), recombeeClientProperties.getToken())
30+
.setRegion(recombeeClientProperties.getRegion());
3131
}
3232

3333
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>com.recombee</groupId>
7+
<artifactId>api-client-parent</artifactId>
8+
<version>4.2.0-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>api-client-spring-boot-3-autoconfigure</artifactId>
11+
<name>Recombee API Client Spring Boot 3 Autoconfiguration</name>
12+
13+
<properties>
14+
<dependency.springboot.version>${spring.boot.3.version}</dependency.springboot.version>
15+
</properties>
16+
17+
<dependencyManagement>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-dependencies</artifactId>
22+
<version>${dependency.springboot.version}</version>
23+
<type>pom</type>
24+
<scope>import</scope>
25+
</dependency>
26+
</dependencies>
27+
</dependencyManagement>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-autoconfigure</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>com.recombee</groupId>
36+
<artifactId>api-client</artifactId>
37+
<optional>true</optional>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-configuration-processor</artifactId>
42+
<optional>true</optional>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-validation</artifactId>
47+
<optional>true</optional>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-starter-test</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
</dependencies>
56+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.recombee.api_client.spring.boot._3.autoconfiguration;
2+
3+
import org.springframework.boot.autoconfigure.AutoConfiguration;
4+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
5+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
6+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
7+
import org.springframework.boot.context.properties.ConfigurationProperties;
8+
import org.springframework.context.annotation.Bean;
9+
10+
import com.recombee.api_client.RecombeeClient;
11+
12+
@AutoConfiguration
13+
@ConditionalOnClass(RecombeeClient.class)
14+
@ConditionalOnProperty(prefix = RecombeeClientAutoconfiguration.DEFAULT_RECOMBEE_CLIENT_PROPERTIES_PREFIX, name = "enabled", matchIfMissing = true)
15+
public class RecombeeClientAutoconfiguration {
16+
17+
public static final String DEFAULT_RECOMBEE_CLIENT_PROPERTIES_PREFIX = "com.recombee.client";
18+
19+
@Bean
20+
@ConditionalOnMissingBean
21+
@ConfigurationProperties(DEFAULT_RECOMBEE_CLIENT_PROPERTIES_PREFIX)
22+
RecombeeClientProperties recombeeClientProperties() {
23+
return new RecombeeClientProperties();
24+
}
25+
26+
@Bean
27+
@ConditionalOnMissingBean
28+
RecombeeClient recombeeClient(RecombeeClientProperties recombeeClientProperties) {
29+
return new RecombeeClient(recombeeClientProperties.getDatabaseId(), recombeeClientProperties.getToken())
30+
.setRegion(recombeeClientProperties.getRegion());
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.recombee.api_client.spring.boot._3.autoconfiguration;
2+
3+
import org.springframework.validation.annotation.Validated;
4+
5+
import com.recombee.api_client.util.Region;
6+
7+
import jakarta.validation.constraints.NotBlank;
8+
import jakarta.validation.constraints.NotNull;
9+
10+
@Validated
11+
public class RecombeeClientProperties {
12+
@NotBlank
13+
private String databaseId;
14+
@NotBlank
15+
private String token;
16+
@NotNull
17+
private Region region;
18+
19+
public RecombeeClientProperties() {
20+
// empty no-args constructor
21+
}
22+
23+
public RecombeeClientProperties(@NotBlank String databaseId, @NotBlank String token, @NotNull Region region) {
24+
this.databaseId = databaseId;
25+
this.token = token;
26+
this.region = region;
27+
}
28+
29+
public String getDatabaseId() {
30+
return databaseId;
31+
}
32+
33+
public void setDatabaseId(String databaseId) {
34+
this.databaseId = databaseId;
35+
}
36+
37+
public String getToken() {
38+
return token;
39+
}
40+
41+
public void setToken(String token) {
42+
this.token = token;
43+
}
44+
45+
public Region getRegion() {
46+
return region;
47+
}
48+
49+
public void setRegion(Region region) {
50+
this.region = region;
51+
}
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.recombee.api_client.spring.boot._3.autoconfiguration.RecombeeClientAutoconfiguration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.recombee.api_client.spring.boot._3.autoconfiguration;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.Test;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
8+
import org.springframework.boot.test.context.SpringBootTest;
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.test.context.ActiveProfiles;
11+
12+
import com.recombee.api_client.RecombeeClient;
13+
import com.recombee.api_client.spring.boot._3.autoconfiguration.RecombeeClientAutoconfigurationTest.TestConfig;
14+
15+
@SpringBootTest(classes = TestConfig.class)
16+
@ActiveProfiles("test")
17+
public class RecombeeClientAutoconfigurationTest {
18+
19+
@Configuration
20+
@EnableAutoConfiguration
21+
public static class TestConfig {
22+
}
23+
24+
@Autowired
25+
private RecombeeClient client;
26+
27+
@Test
28+
public void testAutoConfigurationExecutes() {
29+
assertThat(client).isNotNull();
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
com.recombee.client.database-id=my-database-id
2+
com.recombee.client.token=db-private-token
3+
com.recombee.client.region=US_WEST
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>com.recombee</groupId>
5+
<artifactId>api-client-parent</artifactId>
6+
<version>4.2.0-SNAPSHOT</version>
7+
</parent>
8+
<artifactId>api-client-spring-boot-3-starter</artifactId>
9+
<name>Recombee API Client Spring Boot 3 Starter</name>
10+
<packaging>pom</packaging>
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>com.recombee</groupId>
15+
<artifactId>api-client-spring-boot-3-autoconfigure</artifactId>
16+
</dependency>
17+
<dependency>
18+
<groupId>com.recombee</groupId>
19+
<artifactId>api-client</artifactId>
20+
</dependency>
21+
</dependencies>
22+
</project>

pom.xml

+13-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<properties>
1616
<!-- spring versions -->
1717
<spring.boot.2.version>2.7.18</spring.boot.2.version>
18-
<spring.boot.3.version>3.2.1</spring.boot.3.version>
18+
<spring.boot.3.version>3.4.1</spring.boot.3.version>
1919
</properties>
2020

2121
<licenses>
@@ -67,13 +67,25 @@
6767
<artifactId>api-client-spring-boot-2-starter</artifactId>
6868
<version>${project.version}</version>
6969
</dependency>
70+
<dependency>
71+
<groupId>com.recombee</groupId>
72+
<artifactId>api-client-spring-boot-3-autoconfigure</artifactId>
73+
<version>${project.version}</version>
74+
</dependency>
75+
<dependency>
76+
<groupId>com.recombee</groupId>
77+
<artifactId>api-client-spring-boot-3-starter</artifactId>
78+
<version>${project.version}</version>
79+
</dependency>
7080
</dependencies>
7181
</dependencyManagement>
7282

7383
<modules>
7484
<module>api-client</module>
7585
<module>api-client-spring-boot-2-autoconfigure</module>
7686
<module>api-client-spring-boot-2-starter</module>
87+
<module>api-client-spring-boot-3-autoconfigure</module>
88+
<module>api-client-spring-boot-3-starter</module>
7789
</modules>
7890

7991
<build>

0 commit comments

Comments
 (0)