mirror of https://github.com/dapr/java-sdk.git
Adds autoconfiguration for springboot apps. (#459)
* Adding Dapr Spring Boot Starter. * Move Dapr Spring Boot Starter into existing sdk-springboot project. Co-authored-by: Darren Wang <darren_wang@outlook.com>
This commit is contained in:
parent
efee05681e
commit
6c26942dd5
|
|
@ -173,7 +173,7 @@
|
|||
<goal>repackage</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<mainClass>io.dapr.springboot.DaprMainApplication</mainClass>
|
||||
<mainClass>io.dapr.examples.DaprMainApplication</mainClass>
|
||||
<classifier>exec</classifier>
|
||||
<finalName>dapr-java-sdk-examples</finalName>
|
||||
</configuration>
|
||||
|
|
|
|||
|
|
@ -3,16 +3,15 @@
|
|||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.springboot;
|
||||
package io.dapr.examples;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Dapr's HTTP callback implementation via SpringBoot.
|
||||
* Scanning package io.dapr.springboot is required.
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = {"io.dapr.springboot", "io.dapr.examples"})
|
||||
@SpringBootApplication
|
||||
public class DaprApplication {
|
||||
|
||||
/**
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.springboot;
|
||||
package io.dapr.examples;
|
||||
|
||||
import io.dapr.client.DaprClient;
|
||||
import io.dapr.client.DaprClientBuilder;
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.springboot;
|
||||
package io.dapr.examples;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.springboot;
|
||||
package io.dapr.examples;
|
||||
|
||||
import io.dapr.examples.invoke.http.InvokeClient;
|
||||
import io.opentelemetry.api.OpenTelemetry;
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.springboot;
|
||||
package io.dapr.examples;
|
||||
|
||||
import io.opentelemetry.api.OpenTelemetry;
|
||||
import io.opentelemetry.context.Context;
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.springboot;
|
||||
package io.dapr.examples;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
package io.dapr.examples.actors;
|
||||
|
||||
import io.dapr.actors.runtime.ActorRuntime;
|
||||
import io.dapr.springboot.DaprApplication;
|
||||
import io.dapr.examples.DaprApplication;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
package io.dapr.examples.bindings.http;
|
||||
|
||||
import io.dapr.springboot.DaprApplication;
|
||||
import io.dapr.examples.DaprApplication;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
|
|
|
|||
|
|
@ -170,4 +170,4 @@ For bringing down the kafka cluster that was started in the beginning, run
|
|||
docker-compose -f ./src/main/java/io/dapr/examples/bindings/http/docker-compose-single-kafka.yml down
|
||||
```
|
||||
|
||||
For more details on Dapr Spring Boot integration, please refer to [Dapr Spring Boot](../../../springboot/DaprApplication.java) Application implementation.
|
||||
For more details on Dapr Spring Boot integration, please refer to [Dapr Spring Boot](../../DaprApplication.java) Application implementation.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ package io.dapr.examples.invoke.grpc;
|
|||
import com.google.protobuf.Any;
|
||||
import io.dapr.v1.AppCallbackGrpc;
|
||||
import io.dapr.v1.CommonProtos;
|
||||
import io.dapr.v1.DaprAppCallbackProtos;
|
||||
import io.grpc.Server;
|
||||
import io.grpc.ServerBuilder;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
package io.dapr.examples.invoke.http;
|
||||
|
||||
import io.dapr.springboot.DaprApplication;
|
||||
import io.dapr.examples.DaprApplication;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
|
|
|
|||
|
|
@ -139,4 +139,4 @@ Once running, the output should display the messages sent from invoker in the de
|
|||
|
||||
Method have been remotely invoked and displaying the remote messages.
|
||||
|
||||
For more details on Dapr Spring Boot integration, please refer to [Dapr Spring Boot](../../../springboot/DaprApplication.java) Application implementation.
|
||||
For more details on Dapr Spring Boot integration, please refer to [Dapr Spring Boot](../../DaprApplication.java) Application implementation.
|
||||
|
|
|
|||
|
|
@ -9,9 +9,6 @@ import io.dapr.client.DaprClient;
|
|||
import io.dapr.client.DaprClientBuilder;
|
||||
import io.dapr.client.domain.Metadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import static java.util.Collections.singletonMap;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -243,4 +243,4 @@ No message is consumed by the subscriber app and warnings messages are emitted f
|
|||
|
||||
```
|
||||
|
||||
For more details on Dapr Spring Boot integration, please refer to [Dapr Spring Boot](../../../springboot/DaprApplication.java) Application implementation.
|
||||
For more details on Dapr Spring Boot integration, please refer to [Dapr Spring Boot](../../DaprApplication.java) Application implementation.
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
package io.dapr.examples.pubsub.http;
|
||||
|
||||
import io.dapr.springboot.DaprApplication;
|
||||
import io.dapr.examples.DaprApplication;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import io.dapr.client.DaprClient;
|
||||
import io.dapr.client.DaprClientBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import io.dapr.client.DaprClientBuilder;
|
|||
import io.dapr.client.domain.HttpExtension;
|
||||
import io.dapr.client.domain.InvokeMethodRequest;
|
||||
import io.dapr.client.domain.InvokeMethodRequestBuilder;
|
||||
import io.dapr.springboot.OpenTelemetryConfig;
|
||||
import io.dapr.examples.OpenTelemetryConfig;
|
||||
import io.dapr.utils.TypeRef;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.Tracer;
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ public class TracingDemoMiddleServiceController {
|
|||
}
|
||||
```
|
||||
|
||||
The request attribute `opentelemetry-context` in created by parsing the tracing headers in the [OpenTelemetryInterceptor](../../springboot/OpenTelemetryInterceptor.java) class. See the code below:
|
||||
The request attribute `opentelemetry-context` in created by parsing the tracing headers in the [OpenTelemetryInterceptor](../OpenTelemetryInterceptor.java) class. See the code below:
|
||||
|
||||
```java
|
||||
@Component
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import io.dapr.client.DaprClient;
|
|||
import io.dapr.client.domain.HttpExtension;
|
||||
import io.dapr.client.domain.InvokeMethodRequest;
|
||||
import io.dapr.client.domain.InvokeMethodRequestBuilder;
|
||||
import io.dapr.examples.OpenTelemetryInterceptor;
|
||||
import io.dapr.utils.TypeRef;
|
||||
import io.opentelemetry.context.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -21,7 +22,7 @@ import reactor.core.publisher.Mono;
|
|||
/**
|
||||
* SpringBoot Controller to handle service invocation.
|
||||
*
|
||||
* <p>Instrumentation is handled in {@link io.dapr.springboot.OpenTelemetryInterceptor}.
|
||||
* <p>Instrumentation is handled in {@link OpenTelemetryInterceptor}.
|
||||
*/
|
||||
@RestController
|
||||
public class TracingDemoMiddleServiceController {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@
|
|||
|
||||
package io.dapr.examples.tracing;
|
||||
|
||||
import io.dapr.springboot.DaprApplication;
|
||||
import io.dapr.examples.DaprApplication;
|
||||
import io.dapr.examples.OpenTelemetryInterceptor;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
|
|
@ -14,7 +15,7 @@ import org.apache.commons.cli.Options;
|
|||
/**
|
||||
* Main method to invoke DemoService to test tracing.
|
||||
*
|
||||
* <p>Instrumentation is handled in {@link io.dapr.springboot.OpenTelemetryInterceptor}.
|
||||
* <p>Instrumentation is handled in {@link OpenTelemetryInterceptor}.
|
||||
*
|
||||
* <p>1. Build and install jars:
|
||||
* mvn clean install
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
package io.dapr.examples.tracing;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.dapr.examples.OpenTelemetryInterceptor;
|
||||
import io.opentelemetry.api.trace.Tracer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
|
@ -14,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestHeader;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
|
@ -24,7 +24,7 @@ import java.util.TimeZone;
|
|||
/**
|
||||
* SpringBoot Controller to handle service invocation.
|
||||
*
|
||||
* <p>Instrumentation is handled in {@link io.dapr.springboot.OpenTelemetryInterceptor}.
|
||||
* <p>Instrumentation is handled in {@link OpenTelemetryInterceptor}.
|
||||
*/
|
||||
@RestController
|
||||
public class TracingDemoServiceController {
|
||||
|
|
|
|||
|
|
@ -29,8 +29,21 @@
|
|||
|
||||
<properties>
|
||||
<maven.deploy.skip>false</maven.deploy.skip>
|
||||
<springboot.version>2.3.5.RELEASE</springboot.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${springboot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.dapr</groupId>
|
||||
|
|
@ -88,6 +101,17 @@
|
|||
<version>5.2.10.RELEASE</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.springboot;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Dapr's Spring Boot AutoConfiguration.
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnWebApplication
|
||||
@ComponentScan("io.dapr.springboot")
|
||||
public class DaprAutoConfiguration {
|
||||
}
|
||||
|
|
@ -7,11 +7,8 @@ package io.dapr.springboot;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.dapr.Topic;
|
||||
import io.dapr.client.ObjectSerializer;
|
||||
import io.dapr.serializer.DefaultObjectSerializer;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import org.springframework.http.MediaType;
|
|||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
io.dapr.springboot.DaprAutoConfiguration
|
||||
|
|
@ -11,7 +11,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
/**
|
||||
* Dapr's HTTP callback implementation via SpringBoot.
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = {"io.dapr.springboot", "io.dapr.it.actors.app"})
|
||||
@SpringBootApplication
|
||||
public class TestApplication {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
/**
|
||||
* Dapr's HTTP callback implementation via SpringBoot.
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = {"io.dapr.springboot", "io.dapr.it.actors.services.springboot"})
|
||||
@SpringBootApplication
|
||||
public class DaprApplication {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
/**
|
||||
* Service for subscriber.
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = {"io.dapr.springboot", "io.dapr.it.pubsub.http"})
|
||||
@SpringBootApplication
|
||||
public class SubscriberService {
|
||||
|
||||
public static final String SUCCESS_MESSAGE = "Completed initialization in";
|
||||
|
|
|
|||
Loading…
Reference in New Issue