Reflect grouping in directory structure
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.example.order;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.smoketest.support.assertj.AssertableOutput;
|
||||
import org.springframework.aot.smoketest.support.junit.ApplicationTest;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ApplicationTest
|
||||
class OrderApplicationAotTests {
|
||||
|
||||
@Test
|
||||
void expectedOrderIsLogged(AssertableOutput output) {
|
||||
Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(
|
||||
() -> assertThat(output).hasSingleLineContaining("Items: priority50, -20, -10, 10, none"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.order;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Item {
|
||||
|
||||
String describe();
|
||||
|
||||
}
|
||||
15
framework/order/src/main/java/com/example/order/Item10.java
Normal file
15
framework/order/src/main/java/com/example/order/Item10.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.example.order;
|
||||
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Order(10)
|
||||
class Item10 implements Item {
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "10";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.example.order;
|
||||
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Order(-20)
|
||||
class ItemMinus20 implements Item {
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "-20";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.example.order;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@SpringBootApplication
|
||||
public class OrderApplication {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(OrderApplication.class);
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
SpringApplication.run(OrderApplication.class, args);
|
||||
Thread.currentThread().join(); // To be able to measure memory consumption
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ApplicationRunner run(ObjectProvider<Item> items) {
|
||||
return (args) -> {
|
||||
String itemsDescription = items.orderedStream().map(Item::describe).collect(Collectors.joining(", "));
|
||||
logger.info("Items: " + itemsDescription);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.example.order;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
class OrderConfiguration {
|
||||
|
||||
@Bean
|
||||
Item unorderedItem() {
|
||||
return () -> "none";
|
||||
}
|
||||
|
||||
@Bean
|
||||
PriorityOrderedItem priorityItem50() {
|
||||
return new PriorityOrderedItem(50);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Order(-10)
|
||||
Item itemMinus10() {
|
||||
return () -> "-10";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.example.order;
|
||||
|
||||
import org.springframework.core.PriorityOrdered;
|
||||
|
||||
class PriorityOrderedItem implements Item, PriorityOrdered {
|
||||
|
||||
private final int order;
|
||||
|
||||
public PriorityOrderedItem(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "priority" + this.order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user