Skip to content

Commit fdf7918

Browse files
committed
Merge remote-tracking branch 'remote/master'
2 parents 37c8219 + 6364016 commit fdf7918

File tree

10 files changed

+249
-12
lines changed

10 files changed

+249
-12
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@ The following Spring Core Topics are covered in Jstobigdata.com.
1414
1. [A high-level introduction to Spring Framework](https://jstobigdata.com/spring/a-high-level-introduction-to-spring-framework/)
1515
2. [Inversion of Control and Dependency Injection in Spring](https://jstobigdata.com/spring/inversion-of-control-and-dependency-injection-in-spring/)
1616
3. [Spring Bean Scopes – @Scope annotation](https://jstobigdata.com/spring/spring-bean-scopes-scope-annotation/)
17-
4. [Mapping and Injecting Collections in Spring](https://jstobigdata.com/spring/mapping-and-injecting-collections-in-spring/)
18-
5. [Spring bean Lifecycle Callbacks](https://jstobigdata.com/spring/spring-bean-lifecycle-callbacks/)
19-
6. [Spring bean definition Inheritance](https://jstobigdata.com/spring/spring-bean-definition-inheritance/)
20-
7. [Spring BeanPostProcessor to customize beans](https://jstobigdata.com/spring/spring-beanpostprocessor-to-customize-beans/)
21-
8. [Dependency Injection: @Autowired, @Resource and @Inject](https://jstobigdata.com/spring/dependency-injection-autowired-resource-and-inject/)
22-
9. [Fine-tune auto wiring using @Primary and @Qualifier](https://jstobigdata.com/spring/fine-tune-auto-wiring-using-primary-and-qualifier/)
23-
10. [IoC Container, Bean Factory vs Application Context in Spring](https://jstobigdata.com/spring/ioc-container-application-context-vs-bean-factory-in-spring/)
24-
11. [Managed beans using @Component, @Repository, @Service](https://jstobigdata.com/spring/managed-components-in-spring-component-repository-service/)
25-
12. [Classpath Scanning using @ComponentScan and Filters](https://jstobigdata.com/spring/classpath-scanning-using-componentscan-and-filters/)
26-
13. [Spring @PropertySource to read property files](https://jstobigdata.com/spring/spring-propertysource-to-read-property-files/)
27-
14. [Profiles in Spring to register beans conditionally](https://jstobigdata.com/spring/profiles-in-spring-to-register-beans-conditionally/)
28-
15. [Custom Events and Generic Events in Spring](https://jstobigdata.com/spring/custom-events-and-generic-events-in-spring/)
17+
4. [Use of @Order annotation in Spring framework](https://jstobigdata.com/spring/use-of-order-annotation-in-spring/)
18+
5. [Mapping and Injecting Collections in Spring](https://jstobigdata.com/spring/mapping-and-injecting-collections-in-spring/)
19+
6. [Spring bean Lifecycle Callbacks](https://jstobigdata.com/spring/spring-bean-lifecycle-callbacks/)
20+
7. [Spring bean definition Inheritance](https://jstobigdata.com/spring/spring-bean-definition-inheritance/)
21+
8. [Spring BeanPostProcessor to customize beans](https://jstobigdata.com/spring/spring-beanpostprocessor-to-customize-beans/)
22+
9. [Dependency Injection: @Autowired, @Resource and @Inject](https://jstobigdata.com/spring/dependency-injection-autowired-resource-and-inject/)
23+
10. [Fine-tune auto wiring using @Primary and @Qualifier](https://jstobigdata.com/spring/fine-tune-auto-wiring-using-primary-and-qualifier/)
24+
11. [IoC Container, Bean Factory vs Application Context in Spring](https://jstobigdata.com/spring/ioc-container-application-context-vs-bean-factory-in-spring/)
25+
12. [Managed beans using @Component, @Repository, @Service](https://jstobigdata.com/spring/managed-components-in-spring-component-repository-service/)
26+
13. [Classpath Scanning using @ComponentScan and Filters](https://jstobigdata.com/spring/classpath-scanning-using-componentscan-and-filters/)
27+
14. [Spring @PropertySource to read property files](https://jstobigdata.com/spring/spring-propertysource-to-read-property-files/)
28+
15. [Profiles in Spring to register beans conditionally](https://jstobigdata.com/spring/profiles-in-spring-to-register-beans-conditionally/)
29+
16. [Custom Events and Generic Events in Spring](https://jstobigdata.com/spring/custom-events-and-generic-events-in-spring/)
2930

3031
## Spring AOP Tutorial
3132
This is a complete Spring AOP tutorial without using Spring Boot. This is designed to give you a solid foundation of Spring-AOP fundamentals.

spring-core-order-annotation/pom.xml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>spring-framework-tutorial-parent</artifactId>
7+
<groupId>com.jstobigdata</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
<artifactId>spring-core-order-annotation</artifactId>
12+
<description>Use of Spring's @Order annotation</description>
13+
<dependencies>
14+
15+
<!-- Step-1 Add the dependencies -->
16+
<dependency>
17+
<groupId>org.springframework</groupId>
18+
<artifactId>spring-core</artifactId>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>org.springframework</groupId>
23+
<artifactId>spring-context</artifactId>
24+
</dependency>
25+
26+
<!-- Test Dependencies-->
27+
<dependency>
28+
<groupId>org.junit.jupiter</groupId>
29+
<artifactId>junit-jupiter-api</artifactId>
30+
<scope>test</scope>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.junit.jupiter</groupId>
35+
<artifactId>junit-jupiter-engine</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.springframework</groupId>
41+
<artifactId>spring-test</artifactId>
42+
<scope>test</scope>
43+
</dependency>
44+
</dependencies>
45+
46+
<dependencyManagement>
47+
<dependencies>
48+
<dependency>
49+
<groupId>com.jstobigdata</groupId>
50+
<artifactId>spring-tutorial-boms</artifactId>
51+
<type>pom</type>
52+
<scope>import</scope>
53+
<version>1.0-SNAPSHOT</version>
54+
</dependency>
55+
</dependencies>
56+
</dependencyManagement>
57+
58+
<!-- For Junit-jupiter-->
59+
<build>
60+
<plugins>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-surefire-plugin</artifactId>
64+
<version>3.0.0-M3</version>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
</project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.jsbd.order;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.core.annotation.Order;
7+
8+
import com.jsbd.order.model.NotificationChannel;
9+
10+
@Configuration
11+
@ComponentScan("com.jsbd.order")
12+
public class ApplicationConfig {
13+
14+
15+
@Bean
16+
@Order(2)
17+
public NotificationChannel email(){
18+
// System.out.println("Notification Channel - Email");
19+
return new NotificationChannel("Email");
20+
}
21+
22+
@Bean
23+
@Order(4)
24+
public NotificationChannel twitter(){
25+
// System.out.println("Notification Channel - Twitter");
26+
return new NotificationChannel("Twitter");
27+
}
28+
29+
@Bean
30+
@Order(3)
31+
public NotificationChannel slack(){
32+
// System.out.println("Notification Channel - Slack");
33+
return new NotificationChannel("Slack");
34+
}
35+
36+
@Bean
37+
@Order(1)
38+
public NotificationChannel sms(){
39+
// System.out.println("Notification Channel - Sms");
40+
return new NotificationChannel("Sms");
41+
}
42+
43+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.jsbd.order.model;
2+
3+
public class NotificationChannel {
4+
5+
private String name;
6+
7+
public NotificationChannel(String channelName) {
8+
this.name = channelName;
9+
}
10+
11+
public String getName() {
12+
return name;
13+
}
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.jsbd.order.service;
2+
3+
import org.springframework.core.annotation.Order;
4+
import org.springframework.stereotype.Service;
5+
6+
@Service
7+
@Order(3)
8+
public class EmailNotification implements NotificationHandler {
9+
10+
public EmailNotification() {
11+
System.out.println("EmailNotification Service Created.");
12+
}
13+
14+
@Override
15+
public void send() {
16+
System.out.println("Email Notification Handler");
17+
}
18+
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.jsbd.order.service;
2+
3+
public interface NotificationHandler {
4+
void send();
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.jsbd.order.service;
2+
3+
import org.springframework.core.annotation.Order;
4+
import org.springframework.stereotype.Service;
5+
6+
@Service
7+
@Order(2)
8+
class SlackNotification implements NotificationHandler {
9+
10+
public SlackNotification() {
11+
System.out.println("SlackNotification Service created.");
12+
}
13+
14+
@Override
15+
public void send() {
16+
System.out.println("Slack Notification Handler");
17+
}
18+
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.jsbd.order.service;
2+
3+
import org.springframework.core.annotation.Order;
4+
import org.springframework.stereotype.Service;
5+
6+
@Service
7+
@Order(1)
8+
class SmsNotification implements NotificationHandler {
9+
10+
public SmsNotification() {
11+
System.out.println("SmsNotification Service created.");
12+
}
13+
14+
@Override
15+
public void send() {
16+
System.out.println("SMS Notification Handler");
17+
}
18+
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.jsbd.order.service;
2+
3+
import org.springframework.stereotype.Service;
4+
5+
@Service
6+
// Not an Ordered Service, will be the last in sequence
7+
class TwitterNotification implements NotificationHandler {
8+
9+
public TwitterNotification() {
10+
System.out.println("TwitterNotification Service created.");
11+
}
12+
13+
@Override
14+
public void send() {
15+
System.out.println("Twitter Direct Message Notification Handler");
16+
}
17+
18+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.jsbd.order;
2+
3+
import java.util.List;
4+
5+
import com.jsbd.order.model.NotificationChannel;
6+
import com.jsbd.order.service.NotificationHandler;
7+
8+
import org.junit.jupiter.api.Test;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
11+
12+
@SpringJUnitConfig(ApplicationConfig.class)
13+
public class TestOrderOnCollectionInjection {
14+
15+
@Autowired
16+
private List<NotificationHandler> notificationHandlers;
17+
18+
@Autowired
19+
private List<NotificationChannel> notificationChannels;
20+
21+
@Test
22+
public void testAllChannelSendingOrder() {
23+
notificationHandlers.forEach(NotificationHandler::send);
24+
}
25+
26+
@Test
27+
public void testNotificationChannelBeanOrder(){
28+
notificationChannels.forEach(channel -> System.out.println(channel.getName()));
29+
}
30+
31+
}

0 commit comments

Comments
 (0)