Skip to content

Commit 6e94f03

Browse files
egoebelbeckermaibin
authored andcommitted
1 parent 8e36e2b commit 6e94f03

75 files changed

Lines changed: 965 additions & 50 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎spring-boot-bootstrap/pom.xml‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,6 @@
1515
<relativePath>../parent-boot-2</relativePath>
1616
</parent>
1717

18-
<!-- add dependency management if you have a different parent pom
19-
<dependencyManagement>
20-
<dependencies>
21-
<dependency>
22-
<groupId>org.springframework.boot</groupId>
23-
<artifactId>spring-boot-starter-data-jpa</artifactId>
24-
<version>1.5.10.RELEASE</version>
25-
</dependency>
26-
<dependency>
27-
<groupId>org.springframework.boot</groupId>
28-
<artifactId>spring-boot-dependencies</artifactId>
29-
<version>1.5.10.RELEASE</version>
30-
<type>pom</type>
31-
<scope>import</scope>
32-
</dependency>
33-
</dependencies>
34-
</dependencyManagement>
35-
-->
36-
3718
<dependencies>
3819
<dependency>
3920
<groupId>org.springframework.boot</groupId>

‎spring-boot-ops/README.MD‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### The Course
2+
The "REST With Spring" Classes: http://bit.ly/restwithspring
3+
4+
### Relevant Articles:
5+
6+
- [Intro to Spring Boot Starters](http://www.baeldung.com/spring-boot-starters)
7+
- [A Custom Data Binder in Spring MVC](http://www.baeldung.com/spring-mvc-custom-data-binder)

‎spring-boot-ops/pom.xml‎

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,36 @@
1919
</parent>
2020

2121
<properties>
22+
<!-- The main class to start by executing java -jar -->
23+
<start-class>org.baeldung.demo.DemoApplication</start-class>
2224
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2325
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2426
<java.version>1.8</java.version>
27+
<jquery.version>3.1.1</jquery.version>
28+
<bootstrap.version>3.3.7-1</bootstrap.version>
2529
</properties>
2630

2731
<dependencies>
32+
33+
<!-- add dependency management if you have a different parent pom
34+
<dependencyManagement>
35+
<dependencies>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-data-jpa</artifactId>
39+
<version>1.5.10.RELEASE</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-dependencies</artifactId>
44+
<version>1.5.10.RELEASE</version>
45+
<type>pom</type>
46+
<scope>import</scope>
47+
</dependency>
48+
</dependencies>
49+
</dependencyManagement>
50+
-->
51+
2852
<dependency>
2953
<groupId>org.springframework.boot</groupId>
3054
<artifactId>spring-boot-starter-web</artifactId>
@@ -41,6 +65,77 @@
4165
<artifactId>spring-boot-starter-test</artifactId>
4266
<scope>test</scope>
4367
</dependency>
68+
69+
<dependency>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-starter-data-jpa</artifactId>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>org.springframework.boot</groupId>
76+
<artifactId>spring-boot-starter-mail</artifactId>
77+
</dependency>
78+
79+
<dependency>
80+
<groupId>com.graphql-java</groupId>
81+
<artifactId>graphql-spring-boot-starter</artifactId>
82+
<version>3.6.0</version>
83+
</dependency>
84+
85+
<dependency>
86+
<groupId>org.springframework.boot</groupId>
87+
<artifactId>spring-boot-starter-actuator</artifactId>
88+
</dependency>
89+
90+
<dependency>
91+
<groupId>com.h2database</groupId>
92+
<artifactId>h2</artifactId>
93+
<scope>runtime</scope>
94+
</dependency>
95+
96+
<dependency>
97+
<groupId>javax.persistence</groupId>
98+
<artifactId>javax.persistence-api</artifactId>
99+
<version>2.2</version>
100+
</dependency>
101+
102+
<dependency>
103+
<groupId>org.togglz</groupId>
104+
<artifactId>togglz-spring-boot-starter</artifactId>
105+
<version>2.4.1.Final</version>
106+
</dependency>
107+
108+
<dependency>
109+
<groupId>com.google.guava</groupId>
110+
<artifactId>guava</artifactId>
111+
<version>18.0</version>
112+
</dependency>
113+
114+
<dependency>
115+
<groupId>org.subethamail</groupId>
116+
<artifactId>subethasmtp</artifactId>
117+
<version>3.1.7</version>
118+
<scope>test</scope>
119+
</dependency>
120+
121+
<dependency>
122+
<groupId>org.webjars</groupId>
123+
<artifactId>bootstrap</artifactId>
124+
<version>${bootstrap.version}</version>
125+
</dependency>
126+
127+
<dependency>
128+
<groupId>org.webjars</groupId>
129+
<artifactId>jquery</artifactId>
130+
<version>${jquery.version}</version>
131+
</dependency>
132+
133+
<dependency>
134+
<groupId>com.graphql-java</groupId>
135+
<artifactId>graphql-java-tools</artifactId>
136+
<version>3.2.0</version>
137+
</dependency>
138+
44139
</dependencies>
45140

46141
<build>
@@ -50,8 +145,59 @@
50145
<groupId>org.springframework.boot</groupId>
51146
<artifactId>spring-boot-maven-plugin</artifactId>
52147
</plugin>
148+
149+
<plugin>
150+
<groupId>org.springframework.boot</groupId>
151+
<artifactId>spring-boot-maven-plugin</artifactId>
152+
<version>1.5.2.RELEASE</version>
153+
<executions>
154+
<execution>
155+
<goals>
156+
<goal>repackage</goal>
157+
</goals>
158+
<configuration>
159+
<mainClass>org.baeldung.boot.Application</mainClass>
160+
</configuration>
161+
</execution>
162+
</executions>
163+
</plugin>
53164
</plugins>
54165
</build>
55166

167+
<profiles>
168+
<profile>
169+
<id>autoconfiguration</id>
170+
<build>
171+
<plugins>
172+
<plugin>
173+
<groupId>org.apache.maven.plugins</groupId>
174+
<artifactId>maven-surefire-plugin</artifactId>
175+
<executions>
176+
<execution>
177+
<phase>integration-test</phase>
178+
<goals>
179+
<goal>test</goal>
180+
</goals>
181+
<configuration>
182+
<excludes>
183+
<exclude>**/*LiveTest.java</exclude>
184+
<exclude>**/*IntegrationTest.java</exclude>
185+
</excludes>
186+
<includes>
187+
<include>**/AutoconfigurationTest.java</include>
188+
</includes>
189+
</configuration>
190+
</execution>
191+
</executions>
192+
<configuration>
193+
<systemPropertyVariables>
194+
<test.mime>json</test.mime>
195+
</systemPropertyVariables>
196+
</configuration>
197+
</plugin>
198+
</plugins>
199+
</build>
200+
</profile>
201+
</profiles>
56202

57203
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.baeldung.graphql;
2+
3+
public class Author {
4+
private String id;
5+
private String name;
6+
private String thumbnail;
7+
8+
public String getId() {
9+
return id;
10+
}
11+
12+
public void setId(String id) {
13+
this.id = id;
14+
}
15+
16+
public String getName() {
17+
return name;
18+
}
19+
20+
public void setName(String name) {
21+
this.name = name;
22+
}
23+
24+
public String getThumbnail() {
25+
return thumbnail;
26+
}
27+
28+
public void setThumbnail(String thumbnail) {
29+
this.thumbnail = thumbnail;
30+
}
31+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.graphql;
2+
3+
import java.util.List;
4+
import java.util.Optional;
5+
6+
public class AuthorDao {
7+
private List<Author> authors;
8+
9+
public AuthorDao(List<Author> authors) {
10+
this.authors = authors;
11+
}
12+
13+
public Optional<Author> getAuthor(String id) {
14+
return authors.stream().filter(author -> id.equals(author.getId())).findFirst();
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.graphql;
2+
3+
import java.util.List;
4+
5+
import com.coxautodev.graphql.tools.GraphQLResolver;
6+
7+
public class AuthorResolver implements GraphQLResolver<Author> {
8+
private PostDao postDao;
9+
10+
public AuthorResolver(PostDao postDao) {
11+
this.postDao = postDao;
12+
}
13+
14+
public List<Post> getPosts(Author author) {
15+
return postDao.getAuthorPosts(author.getId());
16+
}
17+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.baeldung.graphql;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
9+
@Configuration
10+
public class GraphqlConfiguration {
11+
@Bean
12+
public PostDao postDao() {
13+
List<Post> posts = new ArrayList<>();
14+
for (int postId = 0; postId < 10; ++postId) {
15+
for (int authorId = 0; authorId < 10; ++authorId) {
16+
Post post = new Post();
17+
post.setId("Post" + authorId + postId);
18+
post.setTitle("Post " + authorId + ":" + postId);
19+
post.setText("Post " + postId + " + by author " + authorId);
20+
post.setAuthorId("Author" + authorId);
21+
posts.add(post);
22+
}
23+
}
24+
return new PostDao(posts);
25+
}
26+
27+
@Bean
28+
public AuthorDao authorDao() {
29+
List<Author> authors = new ArrayList<>();
30+
for (int authorId = 0; authorId < 10; ++authorId) {
31+
Author author = new Author();
32+
author.setId("Author" + authorId);
33+
author.setName("Author " + authorId);
34+
author.setThumbnail("http://example.com/authors/" + authorId);
35+
authors.add(author);
36+
}
37+
return new AuthorDao(authors);
38+
}
39+
40+
@Bean
41+
public PostResolver postResolver(AuthorDao authorDao) {
42+
return new PostResolver(authorDao);
43+
}
44+
45+
@Bean
46+
public AuthorResolver authorResolver(PostDao postDao) {
47+
return new AuthorResolver(postDao);
48+
}
49+
50+
@Bean
51+
public Query query(PostDao postDao) {
52+
return new Query(postDao);
53+
}
54+
55+
@Bean
56+
public Mutation mutation(PostDao postDao) {
57+
return new Mutation(postDao);
58+
}
59+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.graphql;
2+
3+
import java.util.UUID;
4+
5+
import com.coxautodev.graphql.tools.GraphQLMutationResolver;
6+
7+
public class Mutation implements GraphQLMutationResolver {
8+
private PostDao postDao;
9+
10+
public Mutation(PostDao postDao) {
11+
this.postDao = postDao;
12+
}
13+
14+
public Post writePost(String title, String text, String category, String author) {
15+
Post post = new Post();
16+
post.setId(UUID.randomUUID().toString());
17+
post.setTitle(title);
18+
post.setText(text);
19+
post.setCategory(category);
20+
post.setAuthorId(author);
21+
postDao.savePost(post);
22+
23+
return post;
24+
}
25+
}

0 commit comments

Comments
 (0)