Skip to content

Commit

Permalink
chore: set conditional on missing bean by class (openGemini#134)
Browse files Browse the repository at this point in the history
Signed-off-by: weiping-code <[email protected]>
  • Loading branch information
weiping-code authored Oct 5, 2024
1 parent f85ba65 commit e19a2be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
package io.opengemini.client.spring.data.config;

import io.opengemini.client.spring.data.core.DefaultOpenGeminiSerializerFactory;
import io.opengemini.client.spring.data.core.OpenGeminiProperties;
import io.opengemini.client.spring.data.core.OpenGeminiSerializerFactory;
import io.opengemini.client.spring.data.core.ReactiveOpenGeminiTemplate;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import reactor.core.publisher.Flux;

@AutoConfiguration
@ConditionalOnClass({ReactiveOpenGeminiTemplate.class, Flux.class})
@EnableConfigurationProperties(OpenGeminiProperties.class)
public class OpenGeminiReactiveAutoConfiguration {

@Bean
@ConditionalOnMissingBean(name = "reactiveOpenGeminiTemplate")
@ConditionalOnMissingBean(ReactiveOpenGeminiTemplate.class)
public ReactiveOpenGeminiTemplate reactiveOpenGeminiTemplate() {
return new ReactiveOpenGeminiTemplate();
}

@Bean
@ConditionalOnMissingBean(name = "openGeminiSerializerFactory")
@ConditionalOnMissingBean(OpenGeminiSerializerFactory.class)
public OpenGeminiSerializerFactory openGeminiSerializerFactory() {
return new DefaultOpenGeminiSerializerFactory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
public class OpenGeminiAutoConfiguration {

@Bean
@ConditionalOnMissingBean(name = "openGeminiTemplate")
@ConditionalOnMissingBean(OpenGeminiTemplate.class)
public OpenGeminiTemplate openGeminiTemplate(OpenGeminiAsyncClient openGeminiAsyncClient,
OpenGeminiSerializerFactory openGeminiSerializerFactory) {
return new OpenGeminiTemplate(openGeminiAsyncClient, openGeminiSerializerFactory);
}

@Bean
@ConditionalOnMissingBean(name = "openGeminiAsyncClient")
@ConditionalOnMissingBean(OpenGeminiAsyncClient.class)
public OpenGeminiAsyncClient openGeminiAsyncClient(OpenGeminiProperties openGeminiProperties)
throws OpenGeminiException {
return OpenGeminiClientFactory.create(openGeminiProperties.toConfiguration());
}

@Bean
@ConditionalOnMissingBean(name = "openGeminiSerializerFactory")
@ConditionalOnMissingBean(OpenGeminiSerializerFactory.class)
public OpenGeminiSerializerFactory openGeminiSerializerFactory() {
return new DefaultOpenGeminiSerializerFactory();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package io.opengemini.client.spring.data.core;

import io.opengemini.client.api.OpenGeminiException;
import io.opengemini.client.api.Query;

import java.util.List;

public interface MeasurementOperations<T> {

void write(T t) throws OpenGeminiException;
void write(T t);

void write(List<T> list) throws OpenGeminiException;
void write(List<T> list);

List<T> query(Query query);
}

0 comments on commit e19a2be

Please sign in to comment.