first commit

This commit is contained in:
azhwani
2020-08-17 15:12:50 +01:00
parent 2bad67ff38
commit eac28eb90f
7 changed files with 92 additions and 0 deletions
@@ -0,0 +1,12 @@
package com.baeldung.conditionalonproperty;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class NotificationApplication {
public static void main(String[] args) {
SpringApplication.run(NotificationApplication.class, args);
}
}
@@ -0,0 +1,26 @@
package com.baeldung.conditionalonproperty.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baeldung.conditionalonproperty.service.EmailNotification;
import com.baeldung.conditionalonproperty.service.NotificationSender;
import com.baeldung.conditionalonproperty.service.SmsNotification;
@Configuration
public class NotificationConfig {
@Bean(name = "emailNotification")
@ConditionalOnProperty(prefix = "notification", name = "service", havingValue = "email")
public NotificationSender notificationSender() {
return new EmailNotification();
}
@Bean(name = "smsNotification")
@ConditionalOnProperty(prefix = "notification", name = "service", havingValue = "sms")
public NotificationSender notificationSender2() {
return new SmsNotification();
}
}
@@ -0,0 +1,10 @@
package com.baeldung.conditionalonproperty.service;
public class EmailNotification implements NotificationSender {
@Override
public String send(String message) {
return "Email Notification: " + message;
}
}
@@ -0,0 +1,5 @@
package com.baeldung.conditionalonproperty.service;
public interface NotificationSender {
String send(String message);
}
@@ -0,0 +1,10 @@
package com.baeldung.conditionalonproperty.service;
public class SmsNotification implements NotificationSender {
@Override
public String send(String message) {
return "SMS notification: " + message;
}
}
@@ -1,2 +1,4 @@
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto = update
notification.service=email