Skip to content

Commit ed082d3

Browse files
Merge pull request eugenp#2035 from eugenp/BAEL-778
BAEL-778
2 parents 3def35e + cc37377 commit ed082d3

12 files changed

Lines changed: 366 additions & 17 deletions

File tree

‎pom.xml‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45
<groupId>com.baeldung</groupId>
56
<artifactId>parent-modules</artifactId>
@@ -11,19 +12,20 @@
1112
<properties>
1213
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1314
<gib.referenceBranch>refs/heads/master</gib.referenceBranch>
14-
<!-- <gib.enabled>false</gib.enabled>-->
15+
<!-- <gib.enabled>false</gib.enabled>-->
1516
<junit.version>4.12</junit.version>
16-
<org.hamcrest.version>1.3</org.hamcrest.version>
17+
<org.hamcrest.version>1.3</org.hamcrest.version>
1718
<mockito.version>1.10.19</mockito.version>
1819
<!-- logging -->
1920
<org.slf4j.version>1.7.21</org.slf4j.version>
2021
<logback.version>1.1.7</logback.version>
2122
<!-- plugins -->
22-
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
23-
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
23+
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
24+
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
2425
</properties>
2526

2627
<modules>
28+
<module>spring-vertx</module>
2729
<module>aws</module>
2830
<module>akka-streams</module>
2931
<module>algorithms</module>
@@ -70,7 +72,7 @@
7072
<module>immutables</module>
7173

7274
<module>jackson</module>
73-
<!-- <module>java-cassandra</module> -->
75+
<!-- <module>java-cassandra</module> -->
7476
<module>vavr</module>
7577
<module>javax-servlets</module>
7678
<module>javaxval</module>
@@ -122,8 +124,8 @@
122124
<module>selenium-junit-testng</module>
123125
<module>solr</module>
124126
<module>spark-java</module>
125-
<module>spring-5</module>
126-
<module>spring-5-mvc</module>
127+
<module>spring-5</module>
128+
<module>spring-5-mvc</module>
127129
<module>spring-akka</module>
128130
<module>spring-amqp</module>
129131
<module>spring-all</module>
@@ -175,7 +177,7 @@
175177
<module>spring-rest-angular</module>
176178
<module>spring-rest-docs</module>
177179
<module>spring-rest</module>
178-
<module>spring-rest-simple</module>
180+
<module>spring-rest-simple</module>
179181
<module>spring-security-cache-control</module>
180182
<module>spring-security-client/spring-security-jsp-authentication</module>
181183
<module>spring-security-client/spring-security-jsp-authorize</module>
@@ -242,12 +244,12 @@
242244
<groupId>ch.qos.logback</groupId>
243245
<artifactId>logback-core</artifactId>
244246
<version>${logback.version}</version>
245-
</dependency>
247+
</dependency>
246248
<dependency>
247249
<groupId>org.slf4j</groupId>
248250
<artifactId>jcl-over-slf4j</artifactId>
249251
<version>${org.slf4j.version}</version>
250-
</dependency>
252+
</dependency>
251253

252254
<!-- test -->
253255
<dependency>
@@ -267,8 +269,8 @@
267269
<artifactId>hamcrest-library</artifactId>
268270
<version>${org.hamcrest.version}</version>
269271
<scope>test</scope>
270-
</dependency>
271-
<dependency>
272+
</dependency>
273+
<dependency>
272274
<groupId>org.hamcrest</groupId>
273275
<artifactId>hamcrest-all</artifactId>
274276
<version>${org.hamcrest.version}</version>
@@ -280,7 +282,7 @@
280282
<version>${mockito.version}</version>
281283
<scope>test</scope>
282284
</dependency>
283-
</dependencies>
285+
</dependencies>
284286

285287
<build>
286288
<plugins>
@@ -295,7 +297,7 @@
295297
<plugin>
296298
<groupId>org.apache.maven.plugins</groupId>
297299
<artifactId>maven-surefire-plugin</artifactId>
298-
<version>${maven-surefire-plugin.version}</version>
300+
<version>${maven-surefire-plugin.version}</version>
299301
<configuration>
300302
<forkCount>3</forkCount>
301303
<reuseForks>true</reuseForks>
@@ -312,12 +314,12 @@
312314
<plugin>
313315
<groupId>org.apache.maven.plugins</groupId>
314316
<artifactId>maven-compiler-plugin</artifactId>
315-
<version>${maven-compiler-plugin.version}</version>
317+
<version>${maven-compiler-plugin.version}</version>
316318
<configuration>
317319
<source>1.8</source>
318320
<target>1.8</target>
319321
</configuration>
320-
</plugin>
322+
</plugin>
321323
</plugins>
322324
<extensions>
323325
<!--<extension>

‎spring-vertx/pom.xml‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.baeldung</groupId>
7+
<artifactId>vertx-spring</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>vertx-spring</name>
12+
<description>A demo project with vertx spring integration</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.3.RELEASE</version>
18+
<relativePath/>
19+
<!-- lookup parent from repository -->
20+
</parent>
21+
22+
<properties>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
25+
<java.version>1.8</java.version>
26+
<vertx.version>3.4.1</vertx.version>
27+
</properties>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-data-jpa</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-web</artifactId>
37+
<exclusions>
38+
<exclusion>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-tomcat</artifactId>
41+
</exclusion>
42+
</exclusions>
43+
</dependency>
44+
<dependency>
45+
<groupId>io.vertx</groupId>
46+
<artifactId>vertx-core</artifactId>
47+
<version>${vertx.version}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>io.vertx</groupId>
51+
<artifactId>vertx-web</artifactId>
52+
<version>${vertx.version}</version>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>com.h2database</groupId>
57+
<artifactId>h2</artifactId>
58+
<scope>runtime</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-starter-test</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
</dependencies>
66+
67+
<build>
68+
<plugins>
69+
<plugin>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-maven-plugin</artifactId>
72+
</plugin>
73+
</plugins>
74+
</build>
75+
76+
77+
</project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.baeldung.vertxspring;
2+
3+
import javax.annotation.PostConstruct;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.boot.autoconfigure.domain.EntityScan;
9+
import org.springframework.context.annotation.ComponentScan;
10+
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
12+
13+
import com.baeldung.vertxspring.verticles.ServerVerticle;
14+
import com.baeldung.vertxspring.verticles.ServiceVerticle;
15+
16+
import io.vertx.core.Vertx;
17+
18+
@SpringBootApplication
19+
@Configuration
20+
@EnableJpaRepositories("com.baeldung.vertxspring.repository")
21+
@EntityScan("com.baeldung.vertxspring.entity")
22+
@ComponentScan(basePackages = { "com.baeldung" })
23+
public class VertxSpringApplication {
24+
25+
@Autowired
26+
ServerVerticle serverVerticle;
27+
28+
@Autowired
29+
ServiceVerticle serviceVerticle;
30+
31+
public static void main(String[] args) {
32+
SpringApplication.run(VertxSpringApplication.class, args);
33+
}
34+
35+
@PostConstruct
36+
public void deployVerticle() {
37+
final Vertx vertx = Vertx.vertx();
38+
vertx.deployVerticle(serverVerticle);
39+
vertx.deployVerticle(serviceVerticle);
40+
}
41+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.baeldung.vertxspring.entity;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.Id;
5+
6+
import org.springframework.data.annotation.PersistenceConstructor;
7+
8+
@Entity
9+
public class Article {
10+
11+
@Id
12+
private Long id;
13+
private String article;
14+
15+
private Article() {
16+
}
17+
18+
@PersistenceConstructor
19+
public Article(Long id, String article) {
20+
super();
21+
this.id = id;
22+
this.article = article;
23+
}
24+
25+
@Override
26+
public String toString() {
27+
return "Article [id=" + id + ", article=" + article + "]";
28+
}
29+
30+
public Long getArticleId() {
31+
return id;
32+
}
33+
34+
public void setArticleId(Long id) {
35+
this.id = id;
36+
}
37+
38+
public String getArticle() {
39+
return article;
40+
}
41+
42+
public void setArticle(String article) {
43+
this.article = article;
44+
}
45+
46+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.vertxspring.repository;
2+
3+
import org.springframework.data.repository.CrudRepository;
4+
import org.springframework.stereotype.Repository;
5+
6+
import com.baeldung.vertxspring.entity.Article;
7+
8+
@Repository
9+
public interface ArticleRepository extends CrudRepository<Article, Long> {
10+
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.vertxspring.service;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.stereotype.Service;
8+
9+
import com.baeldung.vertxspring.entity.Article;
10+
import com.baeldung.vertxspring.repository.ArticleRepository;
11+
12+
@Service
13+
public class ArticleService {
14+
15+
@Autowired
16+
ArticleRepository articleRepository;
17+
18+
public List<Article> getAllArticle() {
19+
List<Article> articles = new ArrayList<>();
20+
articleRepository.findAll()
21+
.forEach(articles::add);
22+
return articles;
23+
}
24+
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.baeldung.vertxspring.util;
2+
3+
import java.util.Random;
4+
import java.util.UUID;
5+
import java.util.stream.IntStream;
6+
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.CommandLineRunner;
9+
import org.springframework.stereotype.Component;
10+
11+
import com.baeldung.vertxspring.entity.Article;
12+
import com.baeldung.vertxspring.repository.ArticleRepository;
13+
14+
@Component
15+
public class DbBootstrap implements CommandLineRunner {
16+
17+
@Autowired
18+
private ArticleRepository articleRepository;
19+
20+
@Override
21+
public void run(String... arg0) throws Exception {
22+
23+
IntStream.range(0, 10)
24+
.forEach(count -> this.articleRepository.save(new Article(new Random().nextLong(), UUID.randomUUID()
25+
.toString())));
26+
27+
}
28+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.baeldung.vertxspring.verticles;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
import io.vertx.core.AbstractVerticle;
6+
import io.vertx.ext.web.Router;
7+
import io.vertx.ext.web.RoutingContext;
8+
9+
@Component
10+
public class ServerVerticle extends AbstractVerticle {
11+
12+
private void getAllArticlesHandler(RoutingContext routingContext) {
13+
vertx.eventBus()
14+
.<String>send(ServiceVerticle.GET_ALL_ARTICLES, "", result -> {
15+
if (result.succeeded()) {
16+
routingContext.response()
17+
.putHeader("content-type", "application/json")
18+
.setStatusCode(200)
19+
.end(result.result()
20+
.body());
21+
} else {
22+
routingContext.response()
23+
.setStatusCode(500)
24+
.end();
25+
}
26+
});
27+
}
28+
29+
@Override
30+
public void start() throws Exception {
31+
super.start();
32+
33+
Router router = Router.router(vertx);
34+
router.get("/api/baeldung/articles")
35+
.handler(this::getAllArticlesHandler);
36+
37+
vertx.createHttpServer()
38+
.requestHandler(router::accept)
39+
.listen(config().getInteger("http.port", 8080));
40+
}
41+
42+
}

0 commit comments

Comments
 (0)