Skip to content

Commit

Permalink
feat(integrations/spring): add AutoConfiguration class for Spring Mvc…
Browse files Browse the repository at this point in the history
… and Webflux

Signed-off-by: ZhangJian He <shoothzj@gmail.com>
  • Loading branch information
shoothzj committed Aug 18, 2024
1 parent 4cd7c05 commit f263ccc
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.opendal</groupId>
<artifactId>spring-opendal-parent</artifactId>
<artifactId>opendal-spring-parent</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>

Expand All @@ -41,6 +41,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.apache.opendal.spring.config;

import org.apache.opendal.spring.core.DefaultOpenDALReactive;
import org.apache.opendal.spring.core.OpenDALProperties;
import org.apache.opendal.spring.core.OpenDALReactive;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@AutoConfiguration
@EnableConfigurationProperties(OpenDALProperties.class)
public class OpenDALReactiveAutoConfiguration {
private final OpenDALProperties openDALProperties;

public OpenDALReactiveAutoConfiguration(OpenDALProperties openDALProperties) {
this.openDALProperties = openDALProperties;
}

@Bean
@ConditionalOnMissingBean(OpenDALReactive.class)
public DefaultOpenDALReactive opendalReactive(OpenDALProperties openDALProperties) {
return new DefaultOpenDALReactive(openDALProperties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.apache.opendal.spring.config.OpenDALReactiveAutoConfiguration
5 changes: 5 additions & 0 deletions integrations/spring/opendal-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.apache.opendal.spring.config;

import org.apache.opendal.spring.core.DefaultOpenDAL;
import org.apache.opendal.spring.core.OpenDAL;
import org.apache.opendal.spring.core.OpenDALProperties;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@AutoConfiguration
@EnableConfigurationProperties(OpenDALProperties.class)
public class OpenDALAutoConfiguration {
private final OpenDALProperties openDALProperties;

public OpenDALAutoConfiguration(OpenDALProperties openDALProperties) {
this.openDALProperties = openDALProperties;
}

@Bean
@ConditionalOnMissingBean(OpenDAL.class)
public DefaultOpenDAL openGeminiTemplate(OpenDALProperties openDALProperties) {
return new DefaultOpenDAL(openDALProperties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.apache.opendal.spring.config.OpenDALAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.apache.opendal.spring.core;

import org.apache.opendal.AsyncOperator;

public class DefaultOpenDAL implements OpenDAL {
private final AsyncOperator asyncOperator;

public DefaultOpenDAL(OpenDALProperties openDALProperties) {
this.asyncOperator = AsyncOperator.of(openDALProperties.getSchema(), openDALProperties.getConf());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.apache.opendal.spring.core;

import org.apache.opendal.AsyncOperator;

public class DefaultOpenDALReactive implements OpenDALReactive {
private final AsyncOperator asyncOperator;

public DefaultOpenDALReactive(OpenDALProperties openDALProperties) {
this.asyncOperator = AsyncOperator.of(openDALProperties.getSchema(), openDALProperties.getConf());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.apache.opendal.spring.core;

/**
* Interface that specified a basic set of Apache OpenDAL, implemented by {@link DefaultOpenDAL}.
*/
public interface OpenDAL {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.apache.opendal.spring.core;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Map;

/**
* Configuration properties for Apache OpenDAL.
*/
@Getter
@Setter
@ConfigurationProperties("spring.opendal")
public class OpenDALProperties {
private String schema;

private Map<String, String> conf;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.apache.opendal.spring.core;

/**
* Interface that specified a basic set of Apache OpenDAL, implemented by {@link DefaultOpenDALReactive}.
*/
public interface OpenDALReactive {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package org.apache.opendal.spring.core;
18 changes: 12 additions & 6 deletions integrations/spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@
<module>opendal-spring-boot-starter-reactive</module>
</modules>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
</parent>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
Expand All @@ -50,6 +44,18 @@
<spring-boot.version>3.3.2</spring-boot.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down

0 comments on commit f263ccc

Please sign in to comment.