diff --git a/pom.xml b/pom.xml
index 3ecc73a..775a486 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
io.57blocks
sms-spring-boot
- 0.1.1
+ 0.1.2
pom
sms-spring-boot
diff --git a/sms-spring-boot-example/pom.xml b/sms-spring-boot-example/pom.xml
index 8889581..737413b 100644
--- a/sms-spring-boot-example/pom.xml
+++ b/sms-spring-boot-example/pom.xml
@@ -12,7 +12,7 @@
io.57blocks
sms-spring-boot
- 0.1.1
+ 0.1.2
../pom.xml
diff --git a/sms-spring-boot-example/twilio-sms-example/pom.xml b/sms-spring-boot-example/twilio-sms-example/pom.xml
index 2049c20..5323033 100644
--- a/sms-spring-boot-example/twilio-sms-example/pom.xml
+++ b/sms-spring-boot-example/twilio-sms-example/pom.xml
@@ -11,7 +11,7 @@
io.57blocks
sms-spring-boot-example
- 0.1.1
+ 0.1.2
../pom.xml
@@ -23,7 +23,7 @@
io.57blocks
sms-spring-boot-starter
- 0.1.1
+ 0.1.2
io.57blocks
diff --git a/sms-spring-boot-example/twilio-sms-example/src/main/java/io/_57blocks/example/service/GreetingService.java b/sms-spring-boot-example/twilio-sms-example/src/main/java/io/_57blocks/example/service/GreetingService.java
index 26cd39b..4d7e656 100644
--- a/sms-spring-boot-example/twilio-sms-example/src/main/java/io/_57blocks/example/service/GreetingService.java
+++ b/sms-spring-boot-example/twilio-sms-example/src/main/java/io/_57blocks/example/service/GreetingService.java
@@ -14,7 +14,7 @@ public GreetingService(SmsService smsService) {
}
public void sendMessage() {
- this.smsService.send("+12056357762", "+13882201684", "greeting", Locale.ENGLISH,
+ this.smsService.send("+1234567890", "+987654321", "greeting", Locale.ENGLISH,
new Object[]{"Mr. Smith"});
}
diff --git a/sms-spring-boot-starter/pom.xml b/sms-spring-boot-starter/pom.xml
index 5fda116..04ae124 100644
--- a/sms-spring-boot-starter/pom.xml
+++ b/sms-spring-boot-starter/pom.xml
@@ -6,7 +6,7 @@
4.0.0
io.57blocks
- 0.1.1
+ 0.1.2
sms-spring-boot-starter
jar
diff --git a/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/AbstractSmsServiceAutoConfig.java b/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/AbstractSmsServiceAutoConfig.java
index b08aa62..847c8ce 100644
--- a/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/AbstractSmsServiceAutoConfig.java
+++ b/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/AbstractSmsServiceAutoConfig.java
@@ -1,40 +1,19 @@
package io._57blocks.sms.config;
-import io._57blocks.sms.DummySmsService;
-import io._57blocks.sms.SmsService;
import io._57blocks.sms.config.properties.SmsServiceProperties;
import org.springframework.beans.factory.annotation.Autowired;
-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 org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
-@Configuration
-@ConditionalOnClass(SmsService.class)
-@EnableConfigurationProperties(SmsServiceProperties.class)
-public abstract class AbstractSmsServiceAutoConfig {
+abstract class AbstractSmsServiceAutoConfig {
@Autowired
private SmsServiceProperties properties;
- protected ResourceBundleMessageSource smsMessageSource() {
+ ResourceBundleMessageSource smsMessageSource() {
final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename(properties.getMessageBaseName());
return messageSource;
}
- @Bean
- @ConditionalOnMissingBean
- public SmsService smsService() {
- if (properties.getEnabled()) {
- return createSmsService();
- } else {
- return new DummySmsService();
- }
- }
-
- protected abstract SmsService createSmsService();
}
diff --git a/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/DummySmsServiceAutoConfig.java b/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/DummySmsServiceAutoConfig.java
new file mode 100644
index 0000000..31d9fad
--- /dev/null
+++ b/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/DummySmsServiceAutoConfig.java
@@ -0,0 +1,21 @@
+package io._57blocks.sms.config;
+
+import io._57blocks.sms.DummySmsService;
+import io._57blocks.sms.SmsService;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ConditionalOnClass(SmsService.class)
+@ConditionalOnProperty(prefix = "io.57blocks.sms", value = "enabled", havingValue = "false")
+public class DummySmsServiceAutoConfig {
+
+ @Bean
+ @ConditionalOnMissingBean
+ public SmsService smsService() {
+ return new DummySmsService();
+ }
+}
diff --git a/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/SmsServiceTwilioAutoConfig.java b/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/SmsServiceTwilioAutoConfig.java
index 7b13073..5798ed3 100644
--- a/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/SmsServiceTwilioAutoConfig.java
+++ b/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/SmsServiceTwilioAutoConfig.java
@@ -2,15 +2,24 @@
import io._57blocks.sms.SmsService;
import io._57blocks.sms.SmsServiceTwilioImpl;
+import io._57blocks.sms.config.properties.SmsServiceProperties;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+@Configuration
+@EnableConfigurationProperties(SmsServiceProperties.class)
+@ConditionalOnMissingBean(SmsService.class)
@ConditionalOnBean(type = "com.twilio.http.TwilioRestClient")
-@AutoConfigureAfter(name = "io._57blocks.twilio.config.TwilioAutoConfig")
+@AutoConfigureAfter(name = "io._57blocks.twilio.config.TwilioAutoConfig", value = DummySmsServiceAutoConfig.class)
public class SmsServiceTwilioAutoConfig extends AbstractSmsServiceAutoConfig {
- @Override
- protected SmsService createSmsService() {
+ @Bean
+ public SmsService smsService() {
return new SmsServiceTwilioImpl(smsMessageSource());
}
+
}
diff --git a/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/properties/SmsServiceProperties.java b/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/properties/SmsServiceProperties.java
index 0d2109a..0ad9f15 100644
--- a/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/properties/SmsServiceProperties.java
+++ b/sms-spring-boot-starter/src/main/java/io/_57blocks/sms/config/properties/SmsServiceProperties.java
@@ -9,4 +9,12 @@ public class SmsServiceProperties {
private Boolean enabled = Boolean.TRUE;
private String messageBaseName = "/sms/messages";
+
+ public String getMessageBaseName() {
+ if (messageBaseName.startsWith("/")) {
+ messageBaseName = messageBaseName.substring(1);
+ }
+
+ return messageBaseName;
+ }
}
diff --git a/sms-spring-boot-starter/src/main/resources/META-INF/spring.factories b/sms-spring-boot-starter/src/main/resources/META-INF/spring.factories
index 232be2a..7643fbf 100644
--- a/sms-spring-boot-starter/src/main/resources/META-INF/spring.factories
+++ b/sms-spring-boot-starter/src/main/resources/META-INF/spring.factories
@@ -1 +1,3 @@
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=io._57blocks.sms.config.SmsServiceTwilioAutoConfig
\ No newline at end of file
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+io._57blocks.sms.config.DummySmsServiceAutoConfig,\
+io._57blocks.sms.config.SmsServiceTwilioAutoConfig
\ No newline at end of file