Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 883d3a4

Browse files
committed
Switch vanilla-jpa sample to Spring MVC
1 parent 361302c commit 883d3a4

File tree

5 files changed

+19
-54
lines changed

5 files changed

+19
-54
lines changed

spring-graalvm-native-samples/vanilla-jpa/compile.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ echo "Compiling $ARTIFACT with $GRAALVM_VERSION"
2929
{ time native-image \
3030
--verbose \
3131
-H:+RemoveSaturatedTypeFlows \
32+
-Dspring.native.remove-yaml-support=true \
33+
-Dspring.native.remove-jmx-support=true \
34+
-Dspring.native.remove-spel-support=true \
3235
-H:Name=$ARTIFACT \
3336
-cp $CP $MAINCLASS >> output.txt ; } 2>> output.txt
3437

spring-graalvm-native-samples/vanilla-jpa/pom.xml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,7 @@
5050
</dependency>
5151
<dependency>
5252
<groupId>org.springframework.boot</groupId>
53-
<artifactId>spring-boot-starter-webflux</artifactId>
54-
<exclusions>
55-
<exclusion>
56-
<groupId>jakarta.validation</groupId>
57-
<artifactId>jakarta.validation-api</artifactId>
58-
</exclusion>
59-
<exclusion>
60-
<groupId>org.springframework.boot</groupId>
61-
<artifactId>spring-boot-starter-validation</artifactId>
62-
</exclusion>
63-
<exclusion>
64-
<groupId>org.hibernate.validator</groupId>
65-
<artifactId>hibernate-validator</artifactId>
66-
</exclusion>
67-
</exclusions>
53+
<artifactId>spring-boot-starter-web</artifactId>
6854
</dependency>
6955
<dependency>
7056
<groupId>org.springframework.boot</groupId>
@@ -76,6 +62,11 @@
7662
<artifactId>spring-boot-starter-test</artifactId>
7763
<scope>test</scope>
7864
</dependency>
65+
<dependency>
66+
<groupId>org.springframework.boot</groupId>
67+
<artifactId>spring-boot-starter-webflux</artifactId>
68+
<scope>test</scope>
69+
</dependency>
7970
<dependency>
8071
<groupId>org.junit.jupiter</groupId>
8172
<artifactId>junit-jupiter-engine</artifactId>

spring-graalvm-native-samples/vanilla-jpa/src/main/java/app/main/SampleApplication.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@
44

55
import app.main.model.Foo;
66
import app.main.model.FooRepository;
7-
import reactor.core.publisher.Mono;
8-
import reactor.core.scheduler.Schedulers;
97

108
import org.springframework.boot.CommandLineRunner;
119
import org.springframework.boot.SpringApplication;
1210
import org.springframework.boot.autoconfigure.SpringBootApplication;
11+
import org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration;
1312
import org.springframework.context.annotation.Bean;
14-
import org.springframework.web.reactive.function.server.RouterFunction;
13+
import org.springframework.web.servlet.function.RouterFunction;
1514

16-
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
17-
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
18-
import static org.springframework.web.reactive.function.server.ServerResponse.ok;
15+
import static org.springframework.web.servlet.function.RequestPredicates.GET;
16+
import static org.springframework.web.servlet.function.RouterFunctions.route;
17+
import static org.springframework.web.servlet.function.ServerResponse.ok;
1918

20-
@SpringBootApplication(proxyBeanMethods = false)
19+
@SpringBootApplication(proxyBeanMethods = false, exclude = SpringDataWebAutoConfiguration.class)
2120
public class SampleApplication {
2221

2322
private FooRepository entities;
@@ -28,37 +27,21 @@ public SampleApplication(FooRepository entities) {
2827

2928
@Bean
3029
public CommandLineRunner runner() {
31-
System.err.println("+++++++++++");
3230
return args -> {
33-
try {
34-
System.err.println("****");
3531
Optional<Foo> foo = entities.findById(1L);
36-
System.err.println("****: " + foo);
3732
if (!foo.isPresent()) {
3833
entities.save(new Foo("Hello"));
3934
}
40-
}
41-
catch (Exception e) {
42-
e.printStackTrace();
43-
}
4435
};
4536
}
4637

4738
@Bean
4839
public RouterFunction<?> userEndpoints() {
49-
return route(GET("/"), request -> ok().body(
50-
Mono.fromCallable(this::findOne).log().subscribeOn(Schedulers.elastic()),
51-
Foo.class));
40+
return route(GET("/"), request -> ok().body(findOne()));
5241
}
5342

5443
private Foo findOne() {
55-
try {
56-
return entities.findById(1L).get();
57-
}
58-
catch (Exception e) {
59-
e.printStackTrace();
60-
throw e;
61-
}
44+
return entities.findById(1L).get();
6245
}
6346

6447
public static void main(String[] args) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
logging.level.root=debug
1+
#logging.level.root=debug
22
#spring.jpa.show-sql=true
33
#spring.data.jpa.repositories.bootstrap-mode=lazy

spring-graalvm-native-samples/vanilla-jpa/src/test/java/app/main/SampleApplicationTests.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,22 @@
1616

1717
package app.main;
1818

19-
import org.junit.Before;
2019
import org.junit.jupiter.api.Test;
2120

2221
import org.springframework.beans.factory.annotation.Autowired;
23-
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
2422
import org.springframework.boot.test.context.SpringBootTest;
2523
import org.springframework.test.web.reactive.server.WebTestClient;
26-
import org.springframework.web.server.WebHandler;
2724

2825
/**
2926
* @author Dave Syer
3027
*
3128
*/
32-
@SpringBootTest
33-
@AutoConfigureWebTestClient
29+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
3430
public class SampleApplicationTests {
3531

36-
@Autowired
37-
private WebHandler webHandler;
38-
3932
@Autowired
4033
private WebTestClient client;
4134

42-
@Before
43-
public void init() {
44-
client = WebTestClient.bindToWebHandler(webHandler).build();
45-
}
46-
4735
@Test
4836
public void test() {
4937
client.get().uri("/").exchange().expectBody(String.class).isEqualTo("{\"value\":\"Hello\"}");

0 commit comments

Comments
 (0)