Skip to content

Commit 8a56b2a

Browse files
committed
Merge branch 'juliuskrah-master'
2 parents e80bc6e + 97313af commit 8a56b2a

8 files changed

Lines changed: 150 additions & 3 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: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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">
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">
23
<modelVersion>4.0.0</modelVersion>
34
<groupId>com.baeldung</groupId>
45
<artifactId>spring-boot</artifactId>
@@ -11,15 +12,29 @@
1112
<parent>
1213
<groupId>org.springframework.boot</groupId>
1314
<artifactId>spring-boot-starter-parent</artifactId>
14-
<version>1.3.3.RELEASE</version>
15+
<version>1.3.6.RELEASE</version>
16+
<relativePath /> <!-- lookup parent from repository -->
1517
</parent>
1618

19+
<properties>
20+
<!-- The main class to start by executing java -jar -->
21+
<start-class>org.baeldung.boot.DemoApplication</start-class>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
<!-- <spring.version>4.3.0.RELEASE</spring.version> -->
25+
</properties>
26+
1727
<dependencies>
1828
<dependency>
1929
<groupId>org.springframework.boot</groupId>
2030
<artifactId>spring-boot-starter-web</artifactId>
2131
</dependency>
2232

33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-data-jpa</artifactId>
36+
</dependency>
37+
2338
<dependency>
2439
<groupId>org.springframework.boot</groupId>
2540
<artifactId>spring-boot-starter-actuator</artifactId>
@@ -34,6 +49,17 @@
3449
<groupId>io.dropwizard.metrics</groupId>
3550
<artifactId>metrics-core</artifactId>
3651
</dependency>
52+
53+
<dependency>
54+
<groupId>com.h2database</groupId>
55+
<artifactId>h2</artifactId>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-starter-test</artifactId>
61+
<scope>test</scope>
62+
</dependency>
3763
</dependencies>
3864

3965
<build>
@@ -70,4 +96,4 @@
7096

7197
</build>
7298

73-
</project>
99+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
14+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}
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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
34+
}

0 commit comments

Comments
 (0)