From 7e6d1790f76bb3553cb04426edc088ddf8b7a72e Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 26 Jan 2016 10:52:56 +0000 Subject: [PATCH] Add boostrap and eureka-client samples --- bootstrap/pom.xml | 96 +++++++++++++++++++ .../java/demo/BootstrapClientApplication.java | 15 +++ bootstrap/src/main/resources/application.yml | 5 + bootstrap/src/main/resources/bootstrap.yml | 8 ++ bootstrap/src/main/resources/sample.yml | 4 + .../demo/BootstrapClientApplicationTests.java | 30 ++++++ eureka-client/pom.xml | 96 +++++++++++++++++++ .../java/demo/EurekaClientApplication.java | 29 ++++++ .../src/main/resources/application.yml | 3 + .../src/main/resources/bootstrap.yml | 1 + .../demo/EurekaClientApplicationTests.java | 25 +++++ .../src/main/resources/application.yml | 2 +- 12 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 bootstrap/pom.xml create mode 100644 bootstrap/src/main/java/demo/BootstrapClientApplication.java create mode 100644 bootstrap/src/main/resources/application.yml create mode 100644 bootstrap/src/main/resources/bootstrap.yml create mode 100644 bootstrap/src/main/resources/sample.yml create mode 100644 bootstrap/src/test/java/demo/BootstrapClientApplicationTests.java create mode 100644 eureka-client/pom.xml create mode 100644 eureka-client/src/main/java/demo/EurekaClientApplication.java create mode 100644 eureka-client/src/main/resources/application.yml create mode 100644 eureka-client/src/main/resources/bootstrap.yml create mode 100644 eureka-client/src/test/java/demo/EurekaClientApplicationTests.java diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml new file mode 100644 index 0000000..3b0a20b --- /dev/null +++ b/bootstrap/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + org.springframework.cloud + spring-cloud-sample-bootstrap + Brixton.BUILD-SNAPSHOT + jar + + spring-cloud-sample-bootstrap + Demo project for Spring Cloud + + + org.springframework.cloud + spring-cloud-starter-parent + Brixton.BUILD-SNAPSHOT + + + + + UTF-8 + 1.7 + + + + + + + maven-deploy-plugin + + true + + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-starter + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + diff --git a/bootstrap/src/main/java/demo/BootstrapClientApplication.java b/bootstrap/src/main/java/demo/BootstrapClientApplication.java new file mode 100644 index 0000000..9281927 --- /dev/null +++ b/bootstrap/src/main/java/demo/BootstrapClientApplication.java @@ -0,0 +1,15 @@ +package demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author Dave Syer + */ +@SpringBootApplication +public class BootstrapClientApplication { + + public static void main(String[] args) { + SpringApplication.run(BootstrapClientApplication.class, args); + } +} diff --git a/bootstrap/src/main/resources/application.yml b/bootstrap/src/main/resources/application.yml new file mode 100644 index 0000000..e907de6 --- /dev/null +++ b/bootstrap/src/main/resources/application.yml @@ -0,0 +1,5 @@ +server: + display-name: SAMPLE +spring: + application: + name: client diff --git a/bootstrap/src/main/resources/bootstrap.yml b/bootstrap/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..fb274ac --- /dev/null +++ b/bootstrap/src/main/resources/bootstrap.yml @@ -0,0 +1,8 @@ +spring: + config: +# N.B. you don't normally want to do this in a real app. It switches +# off the local application.yml: + name: sample +logging: + level: + org.springframework.boot: DEBUG \ No newline at end of file diff --git a/bootstrap/src/main/resources/sample.yml b/bootstrap/src/main/resources/sample.yml new file mode 100644 index 0000000..ad15abb --- /dev/null +++ b/bootstrap/src/main/resources/sample.yml @@ -0,0 +1,4 @@ +server: + port: 8686 + tomcat: + max-threads: 2 diff --git a/bootstrap/src/test/java/demo/BootstrapClientApplicationTests.java b/bootstrap/src/test/java/demo/BootstrapClientApplicationTests.java new file mode 100644 index 0000000..f4a9420 --- /dev/null +++ b/bootstrap/src/test/java/demo/BootstrapClientApplicationTests.java @@ -0,0 +1,30 @@ +package demo; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.WebIntegrationTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = BootstrapClientApplication.class) +@WebIntegrationTest("server.port=0") +@DirtiesContext +public class BootstrapClientApplicationTests { + + @Autowired + private ServerProperties server; + + @Test + public void contextLoads() throws Exception { + assertEquals(2, this.server.getTomcat().getMaxThreads()); + // The application.yml is never read because spring.config.name=sample + assertEquals("application", this.server.getDisplayName()); + } + +} diff --git a/eureka-client/pom.xml b/eureka-client/pom.xml new file mode 100644 index 0000000..3159679 --- /dev/null +++ b/eureka-client/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + org.springframework.cloud + spring-cloud-sample-eureka-client + Brixton.BUILD-SNAPSHOT + jar + + spring-cloud-sample-eureka-client + Demo project for Spring Cloud + + + org.springframework.cloud + spring-cloud-starter-parent + Brixton.BUILD-SNAPSHOT + + + + + UTF-8 + 1.7 + + + + + + + maven-deploy-plugin + + true + + + + + + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + diff --git a/eureka-client/src/main/java/demo/EurekaClientApplication.java b/eureka-client/src/main/java/demo/EurekaClientApplication.java new file mode 100644 index 0000000..4c01b1d --- /dev/null +++ b/eureka-client/src/main/java/demo/EurekaClientApplication.java @@ -0,0 +1,29 @@ +package demo; + +import java.util.Map; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author Dave Syer + */ +@SpringBootApplication +@EnableDiscoveryClient +@RestController +public class EurekaClientApplication { + + @RequestMapping("/good") + public String good(@RequestParam Map params) { + System.err.println(params); + return "GOOD!"; + } + + public static void main(String[] args) { + SpringApplication.run(EurekaClientApplication.class, args); + } +} diff --git a/eureka-client/src/main/resources/application.yml b/eureka-client/src/main/resources/application.yml new file mode 100644 index 0000000..ee2a629 --- /dev/null +++ b/eureka-client/src/main/resources/application.yml @@ -0,0 +1,3 @@ +spring: + application: + name: client diff --git a/eureka-client/src/main/resources/bootstrap.yml b/eureka-client/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..a3e7b72 --- /dev/null +++ b/eureka-client/src/main/resources/bootstrap.yml @@ -0,0 +1 @@ +debug: true \ No newline at end of file diff --git a/eureka-client/src/test/java/demo/EurekaClientApplicationTests.java b/eureka-client/src/test/java/demo/EurekaClientApplicationTests.java new file mode 100644 index 0000000..d956c20 --- /dev/null +++ b/eureka-client/src/test/java/demo/EurekaClientApplicationTests.java @@ -0,0 +1,25 @@ +package demo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = EurekaClientApplication.class) +@IntegrationTest +@DirtiesContext +public class EurekaClientApplicationTests { + + @Autowired + private EurekaDiscoveryClient client; + + @Test + public void contextLoads() throws Exception { + } + +} diff --git a/eureka-server/src/main/resources/application.yml b/eureka-server/src/main/resources/application.yml index 22c8712..2b4e59e 100644 --- a/eureka-server/src/main/resources/application.yml +++ b/eureka-server/src/main/resources/application.yml @@ -5,4 +5,4 @@ spring: name: eureka eureka: client: - register-with-eureka: false \ No newline at end of file + register-with-eureka: false