diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java
index cc178685de..5a0aee120f 100644
--- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java
+++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2016 the original author or authors.
+ * Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,18 +16,17 @@
package org.springframework.boot.autoconfigure.sendgrid;
+import com.sendgrid.Client;
import com.sendgrid.SendGrid;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
/**
@@ -35,11 +34,12 @@ import org.springframework.context.annotation.Configuration;
*
* @author Maciej Walkowiak
* @author Patrick Bray
+ * @author Andy Wilkinson
* @since 1.3.0
*/
@Configuration
@ConditionalOnClass(SendGrid.class)
-@Conditional(SendGridAutoConfiguration.SendGridPropertyCondition.class)
+@ConditionalOnProperty(prefix = "spring.sendgrid", value = "api-key")
@EnableConfigurationProperties(SendGridProperties.class)
public class SendGridAutoConfiguration {
@@ -52,39 +52,13 @@ public class SendGridAutoConfiguration {
@Bean
@ConditionalOnMissingBean(SendGrid.class)
public SendGrid sendGrid() {
- SendGrid sendGrid = createSendGrid();
if (this.properties.isProxyConfigured()) {
HttpHost proxy = new HttpHost(this.properties.getProxy().getHost(),
this.properties.getProxy().getPort());
- sendGrid.setClient(HttpClientBuilder.create().setProxy(proxy)
- .setUserAgent("sendgrid/" + sendGrid.getVersion() + ";java").build());
+ return new SendGrid(this.properties.getApiKey(),
+ new Client(HttpClientBuilder.create().setProxy(proxy).build()));
}
- return sendGrid;
- }
-
- private SendGrid createSendGrid() {
- if (this.properties.getApiKey() != null) {
- return new SendGrid(this.properties.getApiKey());
- }
- return new SendGrid(this.properties.getUsername(), this.properties.getPassword());
- }
-
- static class SendGridPropertyCondition extends AnyNestedCondition {
-
- SendGridPropertyCondition() {
- super(ConfigurationPhase.PARSE_CONFIGURATION);
- }
-
- @ConditionalOnProperty(prefix = "spring.sendgrid", value = "username")
- static class SendGridUserProperty {
-
- }
-
- @ConditionalOnProperty(prefix = "spring.sendgrid", value = "api-key")
- static class SendGridApiKeyProperty {
-
- }
-
+ return new SendGrid(this.properties.getApiKey());
}
}
diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridProperties.java
index 6a97a2a32a..7f35565d9a 100644
--- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridProperties.java
+++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridProperties.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2016 the original author or authors.
+ * Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,21 +22,12 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* {@link ConfigurationProperties} for SendGrid.
*
* @author Maciej Walkowiak
+ * @author Andy Wilkinson
* @since 1.3.0
*/
@ConfigurationProperties(prefix = "spring.sendgrid")
public class SendGridProperties {
- /**
- * SendGrid username. Alternative to api key.
- */
- private String username;
-
- /**
- * SendGrid password.
- */
- private String password;
-
/**
* SendGrid api key. Alternative to username/password.
*/
@@ -47,22 +38,6 @@ public class SendGridProperties {
*/
private Proxy proxy;
- public String getUsername() {
- return this.username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public String getPassword() {
- return this.password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
public String getApiKey() {
return this.apiKey;
}
diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfigurationTests.java
index 765371d27b..1e2fedac38 100644
--- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfigurationTests.java
+++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfigurationTests.java
@@ -47,19 +47,11 @@ public class SendGridAutoConfigurationTests {
}
}
- @Test
- public void expectedSendGridBeanCreatedUsername() {
- loadContext("spring.sendgrid.username:user", "spring.sendgrid.password:secret");
- SendGrid sendGrid = this.context.getBean(SendGrid.class);
- assertThat(sendGrid).extracting("username").containsExactly("user");
- assertThat(sendGrid).extracting("password").containsExactly("secret");
- }
-
@Test
public void expectedSendGridBeanCreatedApiKey() {
- loadContext("spring.sendgrid.apiKey:SG.SECRET-API-KEY");
+ loadContext("spring.sendgrid.api-key:SG.SECRET-API-KEY");
SendGrid sendGrid = this.context.getBean(SendGrid.class);
- assertThat(sendGrid).extracting("password").containsExactly("SG.SECRET-API-KEY");
+ assertThat(sendGrid).extracting("apiKey").containsExactly("SG.SECRET-API-KEY");
}
@Test(expected = NoSuchBeanDefinitionException.class)
@@ -70,20 +62,20 @@ public class SendGridAutoConfigurationTests {
@Test
public void autoConfigurationNotFiredWhenBeanAlreadyCreated() {
- loadContext(ManualSendGridConfiguration.class, "spring.sendgrid.username:user",
- "spring.sendgrid.password:secret");
+ loadContext(ManualSendGridConfiguration.class,
+ "spring.sendgrid.api-key:SG.SECRET-API-KEY");
SendGrid sendGrid = this.context.getBean(SendGrid.class);
- assertThat(sendGrid).extracting("username").containsExactly("manual-user");
- assertThat(sendGrid).extracting("password").containsExactly("manual-secret");
+ assertThat(sendGrid).extracting("apiKey").containsExactly("SG.CUSTOM_API_KEY");
}
@Test
public void expectedSendGridBeanWithProxyCreated() {
- loadContext("spring.sendgrid.username:user", "spring.sendgrid.password:secret",
+ loadContext("spring.sendgrid.api-key:SG.SECRET-API-KEY",
"spring.sendgrid.proxy.host:localhost",
"spring.sendgrid.proxy.port:5678");
SendGrid sendGrid = this.context.getBean(SendGrid.class);
- assertThat(sendGrid).extracting("client").extracting("routePlanner")
+ assertThat(sendGrid).extracting("client").extracting("httpClient")
+ .extracting("routePlanner")
.hasOnlyElementsOfType(DefaultProxyRoutePlanner.class);
}
@@ -107,7 +99,7 @@ public class SendGridAutoConfigurationTests {
@Bean
SendGrid sendGrid() {
- return new SendGrid("manual-user", "manual-secret");
+ return new SendGrid("SG.CUSTOM_API_KEY", true);
}
}
diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml
index 6d79c769b3..4933f83f4f 100644
--- a/spring-boot-dependencies/pom.xml
+++ b/spring-boot-dependencies/pom.xml
@@ -145,7 +145,7 @@
2.1.0
3.4.0
2.26
- 2.2.2
+ 3.2.0
3.1.0
1.1.1
1.7.25
diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
index 82a76b9d28..5a62db5471 100644
--- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
+++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
@@ -134,8 +134,6 @@ content into your application; rather pick only the properties that you need.
# SENDGRID ({sc-spring-boot-autoconfigure}/sendgrid/SendGridAutoConfiguration.{sc-ext}[SendGridAutoConfiguration])
spring.sendgrid.api-key= # SendGrid api key (alternative to username/password)
- spring.sendgrid.username= # SendGrid account username
- spring.sendgrid.password= # SendGrid account password
spring.sendgrid.proxy.host= # SendGrid proxy host
spring.sendgrid.proxy.port= # SendGrid proxy port