Skip to content

Commit 3df6f80

Browse files
committed
update docker-compose,dockerfile
1 parent c378e1a commit 3df6f80

File tree

13 files changed

+109
-177
lines changed

13 files changed

+109
-177
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ FROM openjdk:8-jdk-alpine
22
RUN addgroup -S spring && adduser -S spring -G spring
33
USER spring:spring
44
RUN mvn clean && mvn package
5-
COPY target/easy-notes-1.0.0.jar app.jar
5+
COPY target/workaround-1.0.0.jar app.jar
66
EXPOSE 8080
77
ENTRYPOINT ["java","-jar","/app.jar"]

Readme.md

-67
Original file line numberDiff line numberDiff line change
@@ -1,67 +0,0 @@
1-
# Spring Boot, MySQL, JPA, Hibernate Rest API Tutorial
2-
3-
Build Restful CRUD API for a simple Note-Taking application using Spring Boot, Mysql, JPA and Hibernate.
4-
5-
## Requirements
6-
7-
1. Java - 1.8.x
8-
9-
2. Maven - 3.x.x
10-
11-
3. Mysql - 5.x.x
12-
13-
## Steps to Setup
14-
15-
**1. Clone the application**
16-
17-
```bash
18-
git clone https://github.com/callicoder/spring-boot-mysql-rest-api-tutorial.git
19-
```
20-
21-
**2. Create Mysql database**
22-
```bash
23-
create database notes_app
24-
```
25-
26-
**3. Change mysql username and password as per your installation**
27-
28-
+ open `src/main/resources/application.properties`
29-
30-
+ change `spring.datasource.username` and `spring.datasource.password` as per your mysql installation
31-
32-
**4. Build and run the app using maven**
33-
34-
```bash
35-
mvn package
36-
java -jar target/easy-notes-1.0.0.jar
37-
```
38-
39-
Alternatively, you can run the app without packaging it using -
40-
41-
```bash
42-
mvn spring-boot:run
43-
```
44-
45-
The app will start running at <http://localhost:8080>.
46-
47-
## Explore Rest APIs
48-
49-
The app defines following CRUD APIs.
50-
51-
GET /api/notes
52-
53-
POST /api/notes
54-
55-
GET /api/notes/{noteId}
56-
57-
PUT /api/notes/{noteId}
58-
59-
DELETE /api/notes/{noteId}
60-
61-
You can test them using postman or any other rest client.
62-
63-
## Learn more
64-
65-
You can find the tutorial for this application on my blog -
66-
67-
<https://www.callicoder.com/spring-boot-rest-api-tutorial-with-mysql-jpa-hibernate/>

pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<modelVersion>4.0.0</modelVersion>
55

66
<groupId>com.example</groupId>
7-
<artifactId>easy-notes</artifactId>
7+
<artifactId>workaround</artifactId>
88
<version>1.0.0</version>
99
<packaging>jar</packaging>
1010

11-
<name>easy-notes</name>
12-
<description>Rest API for a Simple Note Taking Application</description>
11+
<name>workaround</name>
12+
<description>Rest API for a Simple workaround Application</description>
1313

1414
<parent>
1515
<groupId>org.springframework.boot</groupId>

src/main/java/com/example/easynotes/model/Note.java

-81
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
package com.example.easynotes;
1+
package com.example.workaround;
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
66

77
@SpringBootApplication
88
@EnableJpaAuditing
9-
public class EasyNotesApplication {
9+
public class WorkaroundApplication {
1010

1111
public static void main(String[] args) {
12-
SpringApplication.run(EasyNotesApplication.class, args);
12+
SpringApplication.run(WorkaroundApplication.class, args);
1313
}
1414
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.easynotes.controller;
1+
package com.example.workaround.controller;
22

33

44
import org.springframework.web.bind.annotation.GetMapping;
@@ -9,8 +9,8 @@
99
@RequestMapping("/")
1010
public class IndexController {
1111

12-
@GetMapping
13-
public String sayHello() {
14-
return "Hello and Welcome to the EasyNotes application. You can create a new Note by making a POST request to /api/notes endpoint.";
15-
}
12+
@GetMapping
13+
public String sayHello() {
14+
return "Hello and Welcome to the workaround application. You can create a new Note by making a POST request to /api/notes endpoint.";
15+
}
1616
}

src/main/java/com/example/easynotes/controller/LoginController.java renamed to src/main/java/com/example/workaround/controller/LoginController.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.example.easynotes.controller;
1+
package com.example.workaround.controller;
22

3-
import com.example.easynotes.model.User;
3+
import com.example.workaround.model.User;
44

55
import org.springframework.web.bind.annotation.PostMapping;
66
import org.springframework.web.bind.annotation.RequestMapping;
@@ -15,7 +15,7 @@ public class LoginController {
1515

1616

1717
@PostMapping("/login")
18-
public User createNote(User user) {
18+
public User loginUser(User user) {
1919
return user;
2020
}
2121

src/main/java/com/example/easynotes/controller/NoteController.java renamed to src/main/java/com/example/workaround/controller/NoteController.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
package com.example.easynotes.controller;
1+
package com.example.workaround.controller;
22

33
import org.springframework.web.bind.annotation.RequestMapping;
44
import org.springframework.web.bind.annotation.RestController;
55

6-
/**
7-
* Created by rajeevkumarsingh on 27/06/17.
8-
*/
96
@RestController
107
@RequestMapping("/api")
118
public class NoteController {

src/main/java/com/example/easynotes/exception/ResourceNotFoundException.java renamed to src/main/java/com/example/workaround/exception/ResourceNotFoundException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.easynotes.exception;
1+
package com.example.workaround.exception;
22

33
import org.springframework.http.HttpStatus;
44
import org.springframework.web.bind.annotation.ResponseStatus;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.example.workaround.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
5+
import java.util.Date;
6+
7+
import javax.persistence.Column;
8+
import javax.persistence.Entity;
9+
import javax.persistence.EntityListeners;
10+
import javax.persistence.GeneratedValue;
11+
import javax.persistence.GenerationType;
12+
import javax.persistence.Id;
13+
import javax.persistence.Table;
14+
import javax.persistence.Temporal;
15+
import javax.persistence.TemporalType;
16+
import javax.validation.constraints.NotBlank;
17+
18+
import org.springframework.data.annotation.CreatedDate;
19+
import org.springframework.data.annotation.LastModifiedDate;
20+
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
21+
22+
@Entity
23+
@Table(name = "notes")
24+
@EntityListeners(AuditingEntityListener.class)
25+
@JsonIgnoreProperties(value = { "createdAt", "updatedAt" }, allowGetters = true)
26+
public class Note {
27+
@Id
28+
@GeneratedValue(strategy = GenerationType.IDENTITY)
29+
private Long id;
30+
31+
@NotBlank
32+
private String title;
33+
34+
@NotBlank
35+
private String content;
36+
37+
@Column(nullable = false, updatable = false)
38+
@Temporal(TemporalType.TIMESTAMP)
39+
@CreatedDate
40+
private Date createdAt;
41+
42+
@Column(nullable = false)
43+
@Temporal(TemporalType.TIMESTAMP)
44+
@LastModifiedDate
45+
private Date updatedAt;
46+
47+
public Long getId() {
48+
return id;
49+
}
50+
51+
public void setId(Long id) {
52+
this.id = id;
53+
}
54+
55+
public String getTitle() {
56+
return title;
57+
}
58+
59+
public void setTitle(String title) {
60+
this.title = title;
61+
}
62+
63+
public String getContent() {
64+
return content;
65+
}
66+
67+
public void setContent(String content) {
68+
this.content = content;
69+
}
70+
71+
public Date getCreatedAt() {
72+
return createdAt;
73+
}
74+
75+
public void setCreatedAt(Date createdAt) {
76+
this.createdAt = createdAt;
77+
}
78+
79+
public Date getUpdatedAt() {
80+
return updatedAt;
81+
}
82+
83+
public void setUpdatedAt(Date updatedAt) {
84+
this.updatedAt = updatedAt;
85+
}
86+
87+
}

src/main/java/com/example/easynotes/model/User.java renamed to src/main/java/com/example/workaround/model/User.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.easynotes.model;
1+
package com.example.workaround.model;
22

33
import javax.persistence.Entity;
44
import javax.persistence.GeneratedValue;

src/main/java/com/example/easynotes/repository/NoteRepository.java renamed to src/main/java/com/example/workaround/repository/NoteRepository.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
package com.example.easynotes.repository;
1+
package com.example.workaround.repository;
22

3-
import com.example.easynotes.model.Note;
3+
import com.example.workaround.model.Note;
44

55
import org.springframework.data.jpa.repository.JpaRepository;
66
import org.springframework.stereotype.Repository;
77

8-
/**
9-
* Created by rajeevkumarsingh on 27/06/17.
10-
*/
11-
128
@Repository
139
public interface NoteRepository extends JpaRepository<Note, Long> {
1410

src/test/java/com/example/easynotes/EasyNotesApplicationTests.java renamed to src/test/java/com/example/workaround/WorkaroundApplicationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package com.example.easynotes;
1+
package com.example.workaround;
22

33
// @RunWith(SpringRunner.class)
44
// @SpringBootTest
5-
public class EasyNotesApplicationTests {
5+
public class WorkaroundApplicationTests {
66

77
// @Test
88
// public void contextLoads() {

0 commit comments

Comments
 (0)