From fff769ed9dadbb2abf2c028bae08e1ca254212e6 Mon Sep 17 00:00:00 2001 From: Julius Krah Date: Wed, 6 Jul 2016 16:09:24 +0000 Subject: [PATCH 1/4] added source for 'A Guide to Spring Boot in Eclipse' --- spring-boot/.gitignore | 3 + spring-boot/pom.xml | 142 ++++++++++-------- .../org/baeldung/boot/DemoApplication.java | 13 ++ .../java/org/baeldung/boot/model/Foo.java | 40 +++++ .../boot/repository/FooRepository.java | 8 + .../src/main/resources/demo.properties | 6 + .../baeldung/boot/DemoApplicationTests.java | 18 +++ .../boot/repository/FooRepositoryTest.java | 33 ++++ 8 files changed, 204 insertions(+), 59 deletions(-) create mode 100644 spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java create mode 100644 spring-boot/src/main/java/org/baeldung/boot/model/Foo.java create mode 100644 spring-boot/src/main/java/org/baeldung/boot/repository/FooRepository.java create mode 100644 spring-boot/src/main/resources/demo.properties create mode 100644 spring-boot/src/test/java/org/baeldung/boot/DemoApplicationTests.java create mode 100644 spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryTest.java diff --git a/spring-boot/.gitignore b/spring-boot/.gitignore index 24d64373c4..e26d6af438 100644 --- a/spring-boot/.gitignore +++ b/spring-boot/.gitignore @@ -1 +1,4 @@ /target/ +.settings/ +.classpath +.project diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index d0a66197bf..ebd920e395 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -1,73 +1,97 @@ - - 4.0.0 - com.baeldung - spring-boot - 0.0.1-SNAPSHOT - war - Spring Boot Actuator - This is simple boot application for Spring boot actuator test + + 4.0.0 + com.baeldung + spring-boot + 0.0.1-SNAPSHOT + war + Spring Boot Actuator + This is simple boot application for Spring boot actuator test - - - org.springframework.boot - spring-boot-starter-parent - 1.3.3.RELEASE - + + + org.springframework.boot + spring-boot-starter-parent + 1.3.6.RELEASE + + - - - org.springframework.boot - spring-boot-starter-web - + + UTF-8 + 1.8 + + - - org.springframework.boot - spring-boot-starter-actuator - + + + org.springframework.boot + spring-boot-starter-web + - - org.springframework.boot - spring-boot-starter-security - + + org.springframework.boot + spring-boot-starter-data-jpa + - - io.dropwizard.metrics - metrics-core - - + + org.springframework.boot + spring-boot-starter-actuator + - - spring-boot - - - src/main/resources - true - - + + org.springframework.boot + spring-boot-starter-security + - + + io.dropwizard.metrics + metrics-core + - - org.springframework.boot - spring-boot-maven-plugin - + + com.h2database + h2 + - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - + + org.springframework.boot + spring-boot-starter-test + test + + - - org.apache.maven.plugins - maven-war-plugin - + + spring-boot + + + src/main/resources + true + + - + - + + org.springframework.boot + spring-boot-maven-plugin + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-war-plugin + + + + + \ No newline at end of file diff --git a/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java b/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java new file mode 100644 index 0000000000..69e78c3fee --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java @@ -0,0 +1,13 @@ +package org.baeldung.boot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + System.setProperty("spring.config.name", "demo"); + SpringApplication.run(DemoApplication.class, args); + } +} diff --git a/spring-boot/src/main/java/org/baeldung/boot/model/Foo.java b/spring-boot/src/main/java/org/baeldung/boot/model/Foo.java new file mode 100644 index 0000000000..0db0be4db1 --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/boot/model/Foo.java @@ -0,0 +1,40 @@ +package org.baeldung.boot.model; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Foo implements Serializable { + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue + private Integer id; + private String name; + + public Foo() { + } + + public Foo(String name) { + this.name = name; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-boot/src/main/java/org/baeldung/boot/repository/FooRepository.java b/spring-boot/src/main/java/org/baeldung/boot/repository/FooRepository.java new file mode 100644 index 0000000000..de8ce8196d --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/boot/repository/FooRepository.java @@ -0,0 +1,8 @@ +package org.baeldung.boot.repository; + +import org.baeldung.boot.model.Foo; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface FooRepository extends JpaRepository { + public Foo findByName(String name); +} diff --git a/spring-boot/src/main/resources/demo.properties b/spring-boot/src/main/resources/demo.properties new file mode 100644 index 0000000000..649b64f59b --- /dev/null +++ b/spring-boot/src/main/resources/demo.properties @@ -0,0 +1,6 @@ +spring.output.ansi.enabled=never +server.port=7070 + +# Security +security.user.name=admin +security.user.password=password \ No newline at end of file diff --git a/spring-boot/src/test/java/org/baeldung/boot/DemoApplicationTests.java b/spring-boot/src/test/java/org/baeldung/boot/DemoApplicationTests.java new file mode 100644 index 0000000000..4e04334238 --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/boot/DemoApplicationTests.java @@ -0,0 +1,18 @@ +package org.baeldung.boot; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = DemoApplication.class) +@WebAppConfiguration +public class DemoApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryTest.java b/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryTest.java new file mode 100644 index 0000000000..e357800e11 --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryTest.java @@ -0,0 +1,33 @@ +package org.baeldung.boot.repository; + +import static org.junit.Assert.assertThat; + +import org.baeldung.boot.DemoApplicationTests; +import org.baeldung.boot.model.Foo; + +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.is; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +public class FooRepositoryTest extends DemoApplicationTests { + @Autowired + private FooRepository fooRepository; + + @Before + public void setUp() { + fooRepository.save(new Foo("Foo")); + fooRepository.save(new Foo("Bar")); + } + + @Test + public void testFindByName() { + Foo foo = fooRepository.findByName("Bar"); + assertThat(foo, notNullValue()); + assertThat(foo.getId(), is(2)); + } +} From d8a8ad354feeedeb98051ed5deaae9f03bacab4b Mon Sep 17 00:00:00 2001 From: Julius Krah Date: Wed, 6 Jul 2016 16:09:24 +0000 Subject: [PATCH 2/4] added source for 'A Guide to Spring Boot in Eclipse' Added eclipse formatter Added source for 'A Guide to Spring Boot in Eclipse' and added eclipse formatter for Baeldung --- spring-boot/.gitignore | 3 + spring-boot/pom.xml | 142 ++++++++++-------- .../org/baeldung/boot/DemoApplication.java | 13 ++ .../java/org/baeldung/boot/model/Foo.java | 40 +++++ .../boot/repository/FooRepository.java | 8 + .../src/main/resources/demo.properties | 6 + .../baeldung/boot/DemoApplicationTests.java | 18 +++ .../boot/repository/FooRepositoryTest.java | 33 ++++ 8 files changed, 204 insertions(+), 59 deletions(-) create mode 100644 spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java create mode 100644 spring-boot/src/main/java/org/baeldung/boot/model/Foo.java create mode 100644 spring-boot/src/main/java/org/baeldung/boot/repository/FooRepository.java create mode 100644 spring-boot/src/main/resources/demo.properties create mode 100644 spring-boot/src/test/java/org/baeldung/boot/DemoApplicationTests.java create mode 100644 spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryTest.java diff --git a/spring-boot/.gitignore b/spring-boot/.gitignore index 24d64373c4..e26d6af438 100644 --- a/spring-boot/.gitignore +++ b/spring-boot/.gitignore @@ -1 +1,4 @@ /target/ +.settings/ +.classpath +.project diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index d0a66197bf..ebd920e395 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -1,73 +1,97 @@ - - 4.0.0 - com.baeldung - spring-boot - 0.0.1-SNAPSHOT - war - Spring Boot Actuator - This is simple boot application for Spring boot actuator test + + 4.0.0 + com.baeldung + spring-boot + 0.0.1-SNAPSHOT + war + Spring Boot Actuator + This is simple boot application for Spring boot actuator test - - - org.springframework.boot - spring-boot-starter-parent - 1.3.3.RELEASE - + + + org.springframework.boot + spring-boot-starter-parent + 1.3.6.RELEASE + + - - - org.springframework.boot - spring-boot-starter-web - + + UTF-8 + 1.8 + + - - org.springframework.boot - spring-boot-starter-actuator - + + + org.springframework.boot + spring-boot-starter-web + - - org.springframework.boot - spring-boot-starter-security - + + org.springframework.boot + spring-boot-starter-data-jpa + - - io.dropwizard.metrics - metrics-core - - + + org.springframework.boot + spring-boot-starter-actuator + - - spring-boot - - - src/main/resources - true - - + + org.springframework.boot + spring-boot-starter-security + - + + io.dropwizard.metrics + metrics-core + - - org.springframework.boot - spring-boot-maven-plugin - + + com.h2database + h2 + - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - + + org.springframework.boot + spring-boot-starter-test + test + + - - org.apache.maven.plugins - maven-war-plugin - + + spring-boot + + + src/main/resources + true + + - + - + + org.springframework.boot + spring-boot-maven-plugin + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-war-plugin + + + + + \ No newline at end of file diff --git a/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java b/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java new file mode 100644 index 0000000000..8cb413f915 --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java @@ -0,0 +1,13 @@ +package org.baeldung.boot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + System.setProperty("spring.config.name", "demo"); + SpringApplication.run(DemoApplication.class, args); + } +} diff --git a/spring-boot/src/main/java/org/baeldung/boot/model/Foo.java b/spring-boot/src/main/java/org/baeldung/boot/model/Foo.java new file mode 100644 index 0000000000..2adc788c59 --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/boot/model/Foo.java @@ -0,0 +1,40 @@ +package org.baeldung.boot.model; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Foo implements Serializable { + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue + private Integer id; + private String name; + + public Foo() { + } + + public Foo(String name) { + this.name = name; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-boot/src/main/java/org/baeldung/boot/repository/FooRepository.java b/spring-boot/src/main/java/org/baeldung/boot/repository/FooRepository.java new file mode 100644 index 0000000000..09d6975dba --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/boot/repository/FooRepository.java @@ -0,0 +1,8 @@ +package org.baeldung.boot.repository; + +import org.baeldung.boot.model.Foo; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface FooRepository extends JpaRepository { + public Foo findByName(String name); +} diff --git a/spring-boot/src/main/resources/demo.properties b/spring-boot/src/main/resources/demo.properties new file mode 100644 index 0000000000..649b64f59b --- /dev/null +++ b/spring-boot/src/main/resources/demo.properties @@ -0,0 +1,6 @@ +spring.output.ansi.enabled=never +server.port=7070 + +# Security +security.user.name=admin +security.user.password=password \ No newline at end of file diff --git a/spring-boot/src/test/java/org/baeldung/boot/DemoApplicationTests.java b/spring-boot/src/test/java/org/baeldung/boot/DemoApplicationTests.java new file mode 100644 index 0000000000..d8342901ad --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/boot/DemoApplicationTests.java @@ -0,0 +1,18 @@ +package org.baeldung.boot; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = DemoApplication.class) +@WebAppConfiguration +public class DemoApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryTest.java b/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryTest.java new file mode 100644 index 0000000000..13c7e2e533 --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryTest.java @@ -0,0 +1,33 @@ +package org.baeldung.boot.repository; + +import static org.junit.Assert.assertThat; + +import org.baeldung.boot.DemoApplicationTests; +import org.baeldung.boot.model.Foo; + +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.is; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +public class FooRepositoryTest extends DemoApplicationTests { + @Autowired + private FooRepository fooRepository; + + @Before + public void setUp() { + fooRepository.save(new Foo("Foo")); + fooRepository.save(new Foo("Bar")); + } + + @Test + public void testFindByName() { + Foo foo = fooRepository.findByName("Bar"); + assertThat(foo, notNullValue()); + assertThat(foo.getId(), is(2)); + } +} From 3d0ce36f45f4250a7a4f0369fcfd2ed51b9a39aa Mon Sep 17 00:00:00 2001 From: Zeger Hendrikse Date: Fri, 8 Jul 2016 01:08:32 +0200 Subject: [PATCH 3/4] Replaced tabs by spaces --- spring-boot/pom.xml | 158 ++++++++++++++++++++++---------------------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index ebd920e395..94904417e3 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -1,97 +1,97 @@ - 4.0.0 - com.baeldung - spring-boot - 0.0.1-SNAPSHOT - war - Spring Boot Actuator - This is simple boot application for Spring boot actuator test + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + com.baeldung + spring-boot + 0.0.1-SNAPSHOT + war + Spring Boot Actuator + This is simple boot application for Spring boot actuator test - - - org.springframework.boot - spring-boot-starter-parent - 1.3.6.RELEASE - - + + + org.springframework.boot + spring-boot-starter-parent + 1.3.6.RELEASE + + - - UTF-8 - 1.8 - - + + UTF-8 + 1.8 + + - - - org.springframework.boot - spring-boot-starter-web - + + + org.springframework.boot + spring-boot-starter-web + - - org.springframework.boot - spring-boot-starter-data-jpa - + + org.springframework.boot + spring-boot-starter-data-jpa + - - org.springframework.boot - spring-boot-starter-actuator - + + org.springframework.boot + spring-boot-starter-actuator + - - org.springframework.boot - spring-boot-starter-security - + + org.springframework.boot + spring-boot-starter-security + - - io.dropwizard.metrics - metrics-core - + + io.dropwizard.metrics + metrics-core + - - com.h2database - h2 - + + com.h2database + h2 + - - org.springframework.boot - spring-boot-starter-test - test - - + + org.springframework.boot + spring-boot-starter-test + test + + - - spring-boot - - - src/main/resources - true - - + + spring-boot + + + src/main/resources + true + + - + - - org.springframework.boot - spring-boot-maven-plugin - + + org.springframework.boot + spring-boot-maven-plugin + - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + - - org.apache.maven.plugins - maven-war-plugin - + + org.apache.maven.plugins + maven-war-plugin + - + - + - \ No newline at end of file + From 60930fc567a7c6962046b71064b4443c9ba74f40 Mon Sep 17 00:00:00 2001 From: Julius Krah Date: Thu, 7 Jul 2016 23:27:34 +0000 Subject: [PATCH 4/4] Added fix for error 'Unable to find a single main class from the following candidates [org.baeldung.boot.DemoApplication, org.baeldung.main.SpringBootApplication]' --- spring-boot/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index ebd920e395..b2929bedcc 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -17,6 +17,8 @@ + + org.baeldung.boot.DemoApplication UTF-8 1.8