-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
{WIP} examples/spring-devtools #173
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
.DS_Store | ||
old | ||
|
||
# Eclipse | ||
.project | ||
.classpath | ||
.settings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# s2i-java-spring-devtools-example | ||
|
||
This is an project illustrating [Spring Boot Automatic Restarts](../../images/centos/README.md#spring-boot-automatic-restarts). | ||
|
||
|
||
## Local without container | ||
|
||
Run using: | ||
|
||
mvn spring-boot:run | ||
|
||
Open [http://localhost:8080/hello](http://localhost:8080/hello) - see "hello, xorld" ? Wrong. | ||
|
||
Edit `src/main/java/io/okd/s2i/java/spring/example/HelloServlet.java` to change "hello, xorld" to "hello, world". | ||
Use an IDE like Eclipse, with incremental rebuild of the .class file (won't work with a raw text editor). | ||
|
||
Spring Boot devtools will automatically restart and (on reloading /hello) show "hello, world" - good. | ||
|
||
|
||
## Local in container by S2I | ||
|
||
For local building, install s2i either from source https://github.com/openshift/source-to-image/releases/ or e.g. via: | ||
|
||
sudo dnf install source-to-image | ||
|
||
Now to locally build a container using OpenShift Source-To-Image (S2I) use: | ||
|
||
s2i build --copy . fabric8/s2i-java s2i-java-spring-devtools-example | ||
|
||
Now run it like this: | ||
|
||
docker run -p 8080:8080 s2i-java-spring-devtools-example | ||
|
||
and see "hello, xorld" when accessing [http://localhost:8080/hello](http://localhost:8080/hello) - it works, but oups, it's wrong. | ||
|
||
Edit `src/main/java/io/okd/s2i/java/spring/example/HelloServlet.java` to change "hello, xorld" to "hello, world". | ||
Use an IDE like Eclipse, with incremental rebuild of the .class file (won't work with a raw text editor). | ||
Now copy the fixed class file into the running container: | ||
|
||
docker cp src/main/java/io/okd/s2i/java/spring/example/HelloServlet.java $(docker ps --filter ancestor=s2i-java-spring-devtools-example --format "{{.ID}}"):/TODO | ||
|
||
_TODO NOK; cp .class or .java? What is the right path to copy it into? /deployments/ has .jar not .class? /tmp/src(/target) isn't what we want?? Check:_ | ||
|
||
docker exec -it $(docker ps --filter ancestor=s2i-java-spring-devtools-example --format "{{.ID}}") bash | ||
|
||
**Spring Boot devtools will automatically restart, in container, and (on reloading /hello) show "hello, world" - great!** | ||
|
||
|
||
|
||
## In OpenShift via MiniShift | ||
|
||
_[oc rsync](https://docs.okd.io/latest/dev_guide/copy_files_to_container.html)_ | ||
|
||
**TODO** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.okd.s2i.java.spring</groupId> | ||
<artifactId>example</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>example</name> | ||
<description>Example project illustrating Spring Boot Devtools on OpenShift with S2I</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.0.5.RELEASE</version> | ||
<relativePath /> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-devtools</artifactId> | ||
<optional>true</optional> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<!-- WARNING: Do not use devtools in production!!! This is an example, IRL you would only do this in Maven using a custom profile. --> | ||
<excludeDevtools>false</excludeDevtools> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
14 changes: 14 additions & 0 deletions
14
...ples/spring-devtools/src/main/java/io/okd/s2i/java/spring/example/ExampleApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.okd.s2i.java.spring.example; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.web.servlet.ServletComponentScan; | ||
|
||
@SpringBootApplication | ||
@ServletComponentScan | ||
public class ExampleApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ExampleApplication.class, args); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
java/examples/spring-devtools/src/main/java/io/okd/s2i/java/spring/example/HelloServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.okd.s2i.java.spring.example; | ||
|
||
import java.io.IOException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@WebServlet("/hello") | ||
@SuppressWarnings("serial") | ||
public class HelloServlet extends HttpServlet { | ||
|
||
@Override | ||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
response.getOutputStream().print("hello, xorld"); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...spring-devtools/src/test/java/io/okd/s2i/java/spring/example/ExampleApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.okd.s2i.java.spring.example; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT) | ||
public class ExampleApplicationTests { | ||
|
||
@Autowired private TestRestTemplate restTemplate; | ||
|
||
@Test | ||
public void contextLoads() { | ||
} | ||
|
||
@Test | ||
public void testHelloXorld() { | ||
ResponseEntity<String> responseEntity = restTemplate.getForEntity("/hello", String.class); | ||
|
||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); | ||
assertEquals("hello, xorld", responseEntity.getBody()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You must now check that the build log contains a certain string that the fat JAR has been exploded