Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.dapr.client.DaprClient;
import io.dapr.client.DaprClientBuilder;

import java.io.IOException;
import java.util.Map;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand All @@ -21,7 +22,7 @@
/**
* 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,7 +15,7 @@
/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,7 +15,6 @@
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;
Expand All @@ -24,7 +24,7 @@
/**
* 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 {
Expand Down
24 changes: 24 additions & 0 deletions sdk-springboot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Comment on lines +35 to +46

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful of this segment, this will override okhttp version set in dapr-sdk, because spring boot also makes their version declaration in spring-boot-depencies, which conficts with dapr's.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this one I am OK since users would need to solve a version conflict too. If this becomes a problem we would know in our integration tests. Thanks for pointing this out. Learned one more thing.

<dependencies>
<dependency>
<groupId>io.dapr</groupId>
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}
Comment on lines +12 to +19

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use @ComponentScan here, also, you can replace it with @Bean method and @ConditionalOnProperty to provide finer grained control of beans, e.g. you can use property like dapr.controller.enabled to control whether to create the controller bean.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be a breaking change? If not, you could send a PR after this. You have more knowledge about spring boot than me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we can release this version this time, and make additional improments in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. That will also give you time to prepare a PR with your ideas. This one was great BTW. Thanks a lot.

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
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;
Expand Down
2 changes: 2 additions & 0 deletions sdk-springboot/src/main/resources/META-INF/spring.factories
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
io.dapr.springboot.DaprAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Dapr's HTTP callback implementation via SpringBoot.
*/
@SpringBootApplication(scanBasePackages = {"io.dapr.springboot", "io.dapr.it.actors.app"})
Comment thread
artursouza marked this conversation as resolved.
@SpringBootApplication
public class TestApplication {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Dapr's HTTP callback implementation via SpringBoot.
*/
@SpringBootApplication(scanBasePackages = {"io.dapr.springboot", "io.dapr.it.actors.services.springboot"})
@SpringBootApplication
public class DaprApplication {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Service for subscriber.
*/
@SpringBootApplication(scanBasePackages = {"io.dapr.springboot", "io.dapr.it.pubsub.http"})
Comment thread
mukundansundar marked this conversation as resolved.
@SpringBootApplication
public class SubscriberService {

public static final String SUCCESS_MESSAGE = "Completed initialization in";
Expand Down