This commit is contained in:
Phillip Webb 2013-11-04 22:02:20 -08:00
parent d784cb6a88
commit bec1c8f00f
14 changed files with 97 additions and 105 deletions

View File

@ -1,4 +1,4 @@
class Book {
String author
String title
}
String author
String title
}

View File

@ -1,12 +1,12 @@
class Book {
String author
String title
String author
String title
}
class BookTests {
@Test
void testBooks() {
Book book = new Book(author: "Tom Clancy", title: "Threat Vector")
assertEquals("Tom Clancy", book.author)
}
}
@Test
void testBooks() {
Book book = new Book(author: "Tom Clancy", title: "Threat Vector")
assertEquals("Tom Clancy", book.author)
}
}

View File

@ -33,5 +33,4 @@ class FailingSpockTest extends Specification {
//throw new RuntimeException("This should fail!")
true == false
}
}
}

View File

@ -34,15 +34,13 @@ class JmsExample implements CommandLineRunner {
jmsTemplate.send("spring-boot", messageCreator)
latch.await()
}
}
@Log
class Receiver {
CountDownLatch latch
def receive(String message) {
log.info "Received ${message}"
latch.countDown()
}
def receive(String message) {
log.info "Received ${message}"
latch.countDown()
}
}

View File

@ -13,12 +13,12 @@ class JobConfig {
@Bean
protected Tasklet tasklet() {
return new Tasklet() {
@Override
RepeatStatus execute(StepContribution contribution, ChunkContext context) {
return RepeatStatus.FINISHED
}
}
return new Tasklet() {
@Override
RepeatStatus execute(StepContribution contribution, ChunkContext context) {
return RepeatStatus.FINISHED
}
}
}
@Bean
@ -31,5 +31,3 @@ class JobConfig {
return steps.get("step1").tasklet(tasklet()).build()
}
}

View File

@ -7,58 +7,57 @@ import java.util.concurrent.CountDownLatch
@EnableRabbitMessaging
class RabbitExample implements CommandLineRunner {
private CountDownLatch latch = new CountDownLatch(1)
private CountDownLatch latch = new CountDownLatch(1)
@Autowired
RabbitTemplate rabbitTemplate
@Autowired
RabbitTemplate rabbitTemplate
private String queueName = "spring-boot"
private String queueName = "spring-boot"
@Bean
Queue queue() {
new Queue(queueName, false)
}
@Bean
Queue queue() {
new Queue(queueName, false)
}
@Bean
TopicExchange exchange() {
new TopicExchange("spring-boot-exchange")
}
@Bean
TopicExchange exchange() {
new TopicExchange("spring-boot-exchange")
}
/**
* The queue and topic exchange cannot be inlined inside this method and have
* dynamic creation with Spring AMQP work properly.
*/
@Bean
Binding binding(Queue queue, TopicExchange exchange) {
BindingBuilder
.bind(queue)
.to(exchange)
.with("spring-boot")
}
/**
* The queue and topic exchange cannot be inlined inside this method and have
* dynamic creation with Spring AMQP work properly.
*/
@Bean
Binding binding(Queue queue, TopicExchange exchange) {
BindingBuilder
.bind(queue)
.to(exchange)
.with("spring-boot")
}
@Bean
SimpleMessageListenerContainer container(CachingConnectionFactory connectionFactory) {
return new SimpleMessageListenerContainer(
connectionFactory: connectionFactory,
queueNames: [queueName],
messageListener: new MessageListenerAdapter(new Receiver(latch:latch), "receive")
)
}
void run(String... args) {
log.info "Sending RabbitMQ message..."
rabbitTemplate.convertAndSend(queueName, "Greetings from Spring Boot via RabbitMQ")
latch.await()
}
@Bean
SimpleMessageListenerContainer container(CachingConnectionFactory connectionFactory) {
return new SimpleMessageListenerContainer(
connectionFactory: connectionFactory,
queueNames: [queueName],
messageListener: new MessageListenerAdapter(new Receiver(latch:latch), "receive")
)
}
void run(String... args) {
log.info "Sending RabbitMQ message..."
rabbitTemplate.convertAndSend(queueName, "Greetings from Spring Boot via RabbitMQ")
latch.await()
}
}
@Log
class Receiver {
CountDownLatch latch
CountDownLatch latch
def receive(String message) {
log.info "Received ${message}"
latch.countDown()
}
def receive(String message) {
log.info "Received ${message}"
latch.countDown()
}
}

View File

@ -5,12 +5,12 @@ import java.util.concurrent.CountDownLatch;
@EnableReactor
@Log
class Runner implements CommandLineRunner {
@Autowired
Reactor reactor
private CountDownLatch latch = new CountDownLatch(1)
@PostConstruct
void init() {
log.info "Registering consumer"
@ -21,12 +21,10 @@ class Runner implements CommandLineRunner {
log.info "Notified Phil"
latch.await()
}
@Selector(reactor="reactor", value="hello")
void receive(String data) {
log.info "Hello ${data}"
latch.countDown()
}
}
}

View File

@ -6,5 +6,3 @@ class Runner implements CommandLineRunner {
print "Hello World!"
}
}

View File

@ -1,12 +1,12 @@
class HelloSpock extends Specification {
def "length of Spock's and his friends' names"() {
expect:
name.size() == length
def "length of Spock's and his friends' names"() {
expect:
name.size() == length
where:
name | length
"Spock" | 5
"Kirk" | 4
"Scotty" | 6
}
}
where:
name | length
"Spock" | 5
"Kirk" | 4
"Scotty" | 6
}
}

View File

@ -21,5 +21,3 @@ class MyService {
return "World"
}
}

View File

@ -1,7 +1,7 @@
class BookTests {
@Test
void testBooks() {
Book book = new Book(author: "Tom Clancy", title: "Threat Vector")
assertEquals("Tom Clancy", book.author)
}
}
@Test
void testBooks() {
Book book = new Book(author: "Tom Clancy", title: "Threat Vector")
assertEquals("Tom Clancy", book.author)
}
}

View File

@ -6,13 +6,12 @@ package org.test
@EnableTransactionManagement
class Example implements CommandLineRunner {
@Autowired
JdbcTemplate jdbcTemplate
@Transactional
void run(String... args) {
println "Foo count=" + jdbcTemplate.queryForObject("SELECT COUNT(*) from FOO", Integer)
}
@Autowired
JdbcTemplate jdbcTemplate
@Transactional
void run(String... args) {
println "Foo count=" + jdbcTemplate.queryForObject("SELECT COUNT(*) from FOO", Integer)
}
}

View File

@ -19,5 +19,3 @@ class MyService {
return "World!";
}
}

View File

@ -63,12 +63,19 @@ import org.springframework.core.io.ResourceLoader;
public class SpringApplicationBuilder {
private SpringApplication application;
private ConfigurableApplicationContext context;
private SpringApplicationBuilder parent;
private AtomicBoolean running = new AtomicBoolean(false);
private Set<Object> sources = new LinkedHashSet<Object>();
private Map<String, Object> defaultProperties = new LinkedHashMap<String, Object>();
private ConfigurableEnvironment environment;
private Set<String> additionalProfiles = new LinkedHashSet<String>();
private Set<ApplicationContextInitializer<?>> initializers = new LinkedHashSet<ApplicationContextInitializer<?>>();