Skip to content

Commit 305e478

Browse files
committed
Initial project
1 parent 610d0da commit 305e478

17 files changed

+364
-2
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.gradle/
2+
build/
3+
.git/
4+
gradle.properties

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.gradle/
2+
build/

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM gradle:6.0-jdk8 as builder
2+
WORKDIR /workspace
3+
COPY / /workspace/
4+
RUN gradle build
5+
6+
FROM gcr.io/distroless/java:8 as runtime
7+
CMD [ "/opt/app/demo.jar" ]
8+
EXPOSE 8080
9+
COPY --from=builder /workspace/build/libs/springboot-jpa-hana-0.1.0.jar /opt/app/demo.jar

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
1-
# springboot-jpa-hana
2-
A demo Java application leveraging Spring JPA with SAP HANA database
1+
# SpringBoot JPA with HANA
2+
A demo Java application leveraging Spring JPA with SAP HANA database.
3+
4+
## How to build and run?
5+
```bash
6+
$ gradle build
7+
$ java -jar build/libs/springboot-jpa-hana-0.1.0.jar
8+
```
9+
Then open browser and visit http://localhost:8080
10+
11+
## How to run directly
12+
```bash
13+
$ gradle bootRun
14+
```
15+
Then open browser and visit http://localhost:8080
16+
17+
## How to run with Docker
18+
```bash
19+
$ docker build -t springboot-jpa-hana .
20+
$ docker run -v 8080:8080 springboot-jpa-hana
21+
```
22+
Then open browser and visit http://localhost:8080

build.gradle

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
}
5+
dependencies {
6+
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.2.RELEASE")
7+
}
8+
}
9+
10+
apply plugin: 'java'
11+
apply plugin: 'eclipse'
12+
apply plugin: 'idea'
13+
apply plugin: 'org.springframework.boot'
14+
apply plugin: 'io.spring.dependency-management'
15+
16+
bootJar {
17+
baseName = 'springboot-jpa-hana'
18+
version = '0.1.0'
19+
}
20+
21+
repositories {
22+
mavenCentral()
23+
}
24+
25+
sourceCompatibility = 1.8
26+
targetCompatibility = 1.8
27+
28+
dependencies {
29+
compile("org.springframework.boot:spring-boot-starter-web")
30+
// tag::jpa[]
31+
compile('org.springframework.boot:spring-boot-starter-data-jpa')
32+
compile('com.sap.cloud.db.jdbc:ngdbc:2.4.67')
33+
// end::jpa[]
34+
// tag::actuator[]
35+
compile("org.springframework.boot:spring-boot-starter-actuator")
36+
// end::actuator[]
37+
// tag::tests[]
38+
testCompile("org.springframework.boot:spring-boot-starter-test")
39+
testCompile("com.h2database:h2")
40+
// end::tests[]
41+
}
42+

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name='springboot-jpa-hana'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.sap.demo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.sap.demo;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.core.env.Environment;
5+
import org.springframework.web.bind.annotation.*;
6+
7+
@RestController
8+
public class HelloController {
9+
10+
@Autowired
11+
Environment env;
12+
13+
@RequestMapping("/")
14+
public String index() {
15+
return "Greetings from Spring Boot!";
16+
}
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.sap.demo;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.web.bind.annotation.ResponseStatus;
5+
6+
@ResponseStatus(value = HttpStatus.NOT_FOUND)
7+
public class NotFoundError extends RuntimeException {
8+
public NotFoundError() {
9+
super();
10+
}
11+
public NotFoundError(String message, Throwable cause) {
12+
super(message, cause);
13+
}
14+
public NotFoundError(String message) {
15+
super(message);
16+
}
17+
public NotFoundError(Throwable cause) {
18+
super(cause);
19+
}
20+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.sap.demo;
2+
3+
import javax.persistence.*;
4+
5+
@Entity // This tells Hibernate to make a table out of this class
6+
public class User {
7+
@Id
8+
@GeneratedValue(strategy = GenerationType.AUTO)
9+
private Integer id;
10+
11+
private String name;
12+
13+
private String email;
14+
15+
private String locale;
16+
17+
public User() {
18+
}
19+
20+
public User(String name, String email) {
21+
this.name = name;
22+
this.email = email;
23+
}
24+
25+
public Integer getId() {
26+
return id;
27+
}
28+
29+
public void setId(Integer id) {
30+
this.id = id;
31+
}
32+
33+
public String getName() {
34+
return name;
35+
}
36+
37+
public void setName(String name) {
38+
this.name = name;
39+
}
40+
41+
public String getEmail() {
42+
return email;
43+
}
44+
45+
public void setEmail(String email) {
46+
this.email = email;
47+
}
48+
49+
50+
public String getLocale() {
51+
return locale;
52+
}
53+
54+
public void setLocale(String locale) {
55+
this.locale = locale;
56+
}
57+
}

0 commit comments

Comments
 (0)