Fast forward existing prototype work
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.bootstrap</groupId>
|
||||
<artifactId>spring-bootstrap-samples</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-bootstrap-simple-sample</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<main.basedir>${project.basedir}/../..</main.basedir>
|
||||
<start-class>org.springframework.bootstrap.sample.simple.SimpleBootstrapApplication</start-class>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-bootstrap</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.springframework.bootstrap.sample.simple;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.bootstrap.CommandLineRunner;
|
||||
import org.springframework.bootstrap.SpringApplication;
|
||||
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
||||
import org.springframework.bootstrap.sample.simple.service.HelloWorldService;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan
|
||||
public class SimpleBootstrapApplication implements CommandLineRunner {
|
||||
|
||||
// Simple example shows how a command line spring application can execute an
|
||||
// injected bean service. Also demonstrates how you can use @Value to inject
|
||||
// command line args ('--name=whatever') or application properties
|
||||
|
||||
@Autowired
|
||||
private HelloWorldService helloWorldService;
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
System.out.println(this.helloWorldService.getHelloMessage());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(SimpleBootstrapApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.springframework.bootstrap.sample.simple.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class HelloWorldService {
|
||||
|
||||
@Value("${name:World}")
|
||||
private String name;
|
||||
|
||||
public String getHelloMessage() {
|
||||
return "Hello " + name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
name: Phil
|
||||
@@ -0,0 +1,64 @@
|
||||
package org.springframework.bootstrap.sample.simple;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class SimpleBootstrapApplicationTests {
|
||||
|
||||
private static PrintStream savedOutput;
|
||||
private static ByteArrayOutputStream output;
|
||||
private String profiles;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
savedOutput = System.out;
|
||||
output = new ByteArrayOutputStream();
|
||||
System.setOut(new PrintStream(output));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
this.profiles = System.getProperty("spring.profiles.active");
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
if (this.profiles != null) {
|
||||
System.setProperty("spring.profiles.active", this.profiles);
|
||||
} else {
|
||||
System.clearProperty("spring.profiles.active");
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void clear() {
|
||||
System.setOut(savedOutput);
|
||||
}
|
||||
|
||||
private static String getOutput() {
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSettings() throws Exception {
|
||||
SimpleBootstrapApplication.main(new String[0]);
|
||||
String output = getOutput();
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello Phil"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandLoneOverrides() throws Exception {
|
||||
SimpleBootstrapApplication.main(new String[] { "--name=Gordon" });
|
||||
String output = getOutput();
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello Gordon"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user