Skip to content

Commit fff769e

Browse files
committed
added source for 'A Guide to Spring Boot in Eclipse'
1 parent 024b4f8 commit fff769e

8 files changed

Lines changed: 216 additions & 71 deletions

File tree

‎spring-boot/.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
/target/
2+
.settings/
3+
.classpath
4+
.project

‎spring-boot/pom.xml‎

Lines changed: 95 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,97 @@
1-
<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">
2-
<modelVersion>4.0.0</modelVersion>
3-
<groupId>com.baeldung</groupId>
4-
<artifactId>spring-boot</artifactId>
5-
<version>0.0.1-SNAPSHOT</version>
6-
<packaging>war</packaging>
7-
<name>Spring Boot Actuator</name>
8-
<description>This is simple boot application for Spring boot actuator test</description>
9-
10-
<!-- Inherit defaults from Spring Boot -->
11-
<parent>
12-
<groupId>org.springframework.boot</groupId>
13-
<artifactId>spring-boot-starter-parent</artifactId>
14-
<version>1.3.3.RELEASE</version>
15-
</parent>
16-
17-
<dependencies>
18-
<dependency>
19-
<groupId>org.springframework.boot</groupId>
20-
<artifactId>spring-boot-starter-web</artifactId>
21-
</dependency>
22-
23-
<dependency>
24-
<groupId>org.springframework.boot</groupId>
25-
<artifactId>spring-boot-starter-actuator</artifactId>
26-
</dependency>
27-
28-
<dependency>
29-
<groupId>org.springframework.boot</groupId>
30-
<artifactId>spring-boot-starter-security</artifactId>
31-
</dependency>
32-
33-
<dependency>
34-
<groupId>io.dropwizard.metrics</groupId>
35-
<artifactId>metrics-core</artifactId>
36-
</dependency>
37-
</dependencies>
38-
39-
<build>
40-
<finalName>spring-boot</finalName>
41-
<resources>
42-
<resource>
43-
<directory>src/main/resources</directory>
44-
<filtering>true</filtering>
45-
</resource>
46-
</resources>
47-
48-
<plugins>
49-
50-
<plugin>
51-
<groupId>org.springframework.boot</groupId>
52-
<artifactId>spring-boot-maven-plugin</artifactId>
53-
</plugin>
54-
55-
<plugin>
56-
<groupId>org.apache.maven.plugins</groupId>
57-
<artifactId>maven-compiler-plugin</artifactId>
58-
<configuration>
59-
<source>1.8</source>
60-
<target>1.8</target>
61-
</configuration>
62-
</plugin>
63-
64-
<plugin>
65-
<groupId>org.apache.maven.plugins</groupId>
66-
<artifactId>maven-war-plugin</artifactId>
67-
</plugin>
68-
69-
</plugins>
70-
71-
</build>
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>spring-boot</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>war</packaging>
8+
<name>Spring Boot Actuator</name>
9+
<description>This is simple boot application for Spring boot actuator test</description>
10+
11+
<!-- Inherit defaults from Spring Boot -->
12+
<parent>
13+
<groupId>org.springframework.boot</groupId>
14+
<artifactId>spring-boot-starter-parent</artifactId>
15+
<version>1.3.6.RELEASE</version>
16+
<relativePath /> <!-- lookup parent from repository -->
17+
</parent>
18+
19+
<properties>
20+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21+
<java.version>1.8</java.version>
22+
<!-- <spring.version>4.3.0.RELEASE</spring.version> -->
23+
</properties>
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-web</artifactId>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-data-jpa</artifactId>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-actuator</artifactId>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-security</artifactId>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>io.dropwizard.metrics</groupId>
48+
<artifactId>metrics-core</artifactId>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>com.h2database</groupId>
53+
<artifactId>h2</artifactId>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-starter-test</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
</dependencies>
62+
63+
<build>
64+
<finalName>spring-boot</finalName>
65+
<resources>
66+
<resource>
67+
<directory>src/main/resources</directory>
68+
<filtering>true</filtering>
69+
</resource>
70+
</resources>
71+
72+
<plugins>
73+
74+
<plugin>
75+
<groupId>org.springframework.boot</groupId>
76+
<artifactId>spring-boot-maven-plugin</artifactId>
77+
</plugin>
78+
79+
<plugin>
80+
<groupId>org.apache.maven.plugins</groupId>
81+
<artifactId>maven-compiler-plugin</artifactId>
82+
<configuration>
83+
<source>1.8</source>
84+
<target>1.8</target>
85+
</configuration>
86+
</plugin>
87+
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-war-plugin</artifactId>
91+
</plugin>
92+
93+
</plugins>
94+
95+
</build>
7296

7397
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.baeldung.boot;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class DemoApplication {
8+
9+
public static void main(String[] args) {
10+
System.setProperty("spring.config.name", "demo");
11+
SpringApplication.run(DemoApplication.class, args);
12+
}
13+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.baeldung.boot.model;
2+
3+
import java.io.Serializable;
4+
5+
import javax.persistence.Entity;
6+
import javax.persistence.GeneratedValue;
7+
import javax.persistence.Id;
8+
9+
@Entity
10+
public class Foo implements Serializable {
11+
private static final long serialVersionUID = 1L;
12+
@Id
13+
@GeneratedValue
14+
private Integer id;
15+
private String name;
16+
17+
public Foo() {
18+
}
19+
20+
public Foo(String name) {
21+
this.name = name;
22+
}
23+
24+
public Integer getId() {
25+
return id;
26+
}
27+
28+
public void setId(Integer id) {
29+
this.id = id;
30+
}
31+
32+
public String getName() {
33+
return name;
34+
}
35+
36+
public void setName(String name) {
37+
this.name = name;
38+
}
39+
40+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.baeldung.boot.repository;
2+
3+
import org.baeldung.boot.model.Foo;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
public interface FooRepository extends JpaRepository<Foo, Integer> {
7+
public Foo findByName(String name);
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spring.output.ansi.enabled=never
2+
server.port=7070
3+
4+
# Security
5+
security.user.name=admin
6+
security.user.password=password
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.baeldung.boot;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.SpringApplicationConfiguration;
6+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
7+
import org.springframework.test.context.web.WebAppConfiguration;
8+
9+
@RunWith(SpringJUnit4ClassRunner.class)
10+
@SpringApplicationConfiguration(classes = DemoApplication.class)
11+
@WebAppConfiguration
12+
public class DemoApplicationTests {
13+
14+
@Test
15+
public void contextLoads() {
16+
}
17+
18+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.baeldung.boot.repository;
2+
3+
import static org.junit.Assert.assertThat;
4+
5+
import org.baeldung.boot.DemoApplicationTests;
6+
import org.baeldung.boot.model.Foo;
7+
8+
import static org.hamcrest.Matchers.notNullValue;
9+
import static org.hamcrest.Matchers.is;
10+
11+
import org.junit.Before;
12+
import org.junit.Test;
13+
import org.springframework.beans.factory.annotation.Autowired;
14+
import org.springframework.transaction.annotation.Transactional;
15+
16+
@Transactional
17+
public class FooRepositoryTest extends DemoApplicationTests {
18+
@Autowired
19+
private FooRepository fooRepository;
20+
21+
@Before
22+
public void setUp() {
23+
fooRepository.save(new Foo("Foo"));
24+
fooRepository.save(new Foo("Bar"));
25+
}
26+
27+
@Test
28+
public void testFindByName() {
29+
Foo foo = fooRepository.findByName("Bar");
30+
assertThat(foo, notNullValue());
31+
assertThat(foo.getId(), is(2));
32+
}
33+
}

0 commit comments

Comments
 (0)