Skip to content
This repository was archived by the owner on Mar 13, 2021. It is now read-only.

Commit 41f3a31

Browse files
dsyertrisberg
authored andcommitted
Verify main class is detected in fat jar (#80)
* The deployer in spring cloud function will detect a main class from the jar file if it is a Spring Boot jar. * Update Spring Boot to 1.5.13
1 parent b71f653 commit 41f3a31

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ file, which can be shaded with all required dependencies, or it can be
1515
a Spring Boot fat jar (with dependencies nested in
1616
`BOOT-INF/lib`). Simple functions that do not require any dependencies
1717
work just fine. The simplest form of the handler is a class name that
18-
can be instantiated (with a default constructor). More complex creation scenarios can be handled by giving the handler in the form `<bean>&main=<main>` where
18+
can be instantiated (with a default constructor). More complex creation scenarios can be handled by giving the handler in the form `<bean>[&main=<main>]` where
1919

2020
* `<bean>` is a class name or bean name, and
2121
* `<main` is a Spring `@Configuration` class to create an application context
2222

2323
If you provide a `main` parameter you need to include Spring Boot and
24-
all the other dependencies of the context in your archive. If the
24+
all the other dependencies of the context in your archive. A Spring
25+
Boot jar file does not need an explicit `main` (there is one in the
26+
`MANIFEST.MF`), but if you supply one it will be used. If the
2527
`Function` has POJO (i.e. not generic JDK classes) as parameter types,
2628
then you also need to depend on `spring-cloud-function-context` (and
2729
include that in the archive).
@@ -32,10 +34,16 @@ Example:
3234
riff init java -i greetings -a target/greeter-1.0.0.jar --handler=functions.Greeter
3335
```
3436

35-
Example with Spring application context (Note: you need to add quotes around the handler value since it contains an `&`)
37+
Example with Spring Boot application:
3638

3739
```
38-
riff init java -i greetings -a target/greeter-1.0.0.jar --handler='greeter&main=functions.Application'
40+
riff init java -i greetings -a target/greeter-1.0.0.jar --handler=greeter
41+
```
42+
43+
Example with Spring application context and an explicit main (Note: you need to add quotes around the handler value since it contains an `&`)
44+
45+
```
46+
riff init java -i greetings -a target/greeter-1.0.0.jar --handler='greeter&main=functions.FunctionApp'
3947
```
4048

4149
As long as the dependencies are included in the archive correctly, you
@@ -62,10 +70,12 @@ classpath archive, which can be a jar file or a directory, together
6270
with parameters:
6371

6472
* `handler`: the class name of a `Function` to execute, or (when
65-
`main` is also provided) a bean name of a `Function`.
66-
* `main`: the class name of a Spring `@Configuration` that can be used
67-
to create a Spring application context, in which the `handler` is
68-
defined.
73+
`main` is also used) a bean name of a `Function`. Can also be a
74+
comma, or pipe-separated list of functions, which are composed
75+
together at runtime.
76+
* `main`: (optional) the class name of a Spring `@Configuration` that
77+
can be used to create a Spring application context, in which the
78+
`handler` is defined.
6979

7080
The jar archive can also be a comma-separated list of archive
7181
locations, in case you need to compose things together.

pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<parent>
1212
<groupId>org.springframework.boot</groupId>
1313
<artifactId>spring-boot-starter-parent</artifactId>
14-
<version>1.5.12.RELEASE</version>
14+
<version>1.5.13.RELEASE</version>
1515
<relativePath /> <!-- lookup parent from repository -->
1616
</parent>
1717

@@ -21,7 +21,6 @@
2121
<java.version>1.8</java.version>
2222
<spring-cloud.version>Edgware.SR3</spring-cloud.version>
2323
<spring-cloud-function.version>1.0.0.BUILD-SNAPSHOT</spring-cloud-function.version>
24-
<spring-cloud-deployer.version>1.2.2.RELEASE</spring-cloud-deployer.version>
2524
<grpc.version>1.8.0</grpc.version>
2625
<reactor.version>3.2.0.M1</reactor.version>
2726
<dockerfile-maven.version>1.3.6</dockerfile-maven.version>

src/test/java/io/projectriff/invoker/FatJarPojoTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ public void check() {
7070
@Test
7171
public void fatJar() throws Exception {
7272
runner.run("--server.port=" + port, "--grpc.port=0",
73-
"--function.uri=" + sampleJar.toURI()
74-
+ "?handler=uppercase&main=com.example.SampleApplication");
73+
"--function.uri=" + sampleJar.toURI() + "?handler=uppercase");
7574
ResponseEntity<String> result = rest.exchange(RequestEntity
7675
.post(new URI("http://localhost:" + port + "/"))
7776
.contentType(MediaType.APPLICATION_JSON).body("{\"value\":\"foo\"}"),
@@ -82,9 +81,8 @@ public void fatJar() throws Exception {
8281

8382
@Test
8483
public void fatJarAndDirectory() throws Exception {
85-
runner.run("--server.port=" + port, "--grpc.port=0",
86-
"--function.uri=" + sampleDir.toURI() + "," + sampleJar.toURI()
87-
+ "?handler=uppercase&main=com.example.SampleApplication");
84+
runner.run("--server.port=" + port, "--grpc.port=0", "--function.uri="
85+
+ sampleDir.toURI() + "," + sampleJar.toURI() + "?handler=uppercase");
8886
ResponseEntity<String> result = rest.exchange(RequestEntity
8987
.post(new URI("http://localhost:" + port + "/"))
9088
.contentType(MediaType.APPLICATION_JSON).body("{\"value\":\"foo\"}"),

0 commit comments

Comments
 (0)