Skip to content

Commit b4622b1

Browse files
committed
Добавление в проект Spring Boot Starter Data Jpa
1 parent ea32e4a commit b4622b1

File tree

7 files changed

+144
-0
lines changed

7 files changed

+144
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ Liquibase (snakeyaml:1.26), lombok:1.18, slf4j:1.7 + jdbc4.1:(1.16)
1212

1313
// Описание запуска проекта, стек //
1414

15+
### SpringBootStarter
16+
17+
**Стек:**
18+
Spring Boot Starter Data Jpa + Java16 + Postgres (42.2.5) <br>
19+
20+
**Other:**
21+
jstl , lombok:1.18, TomCat 9.0.46
22+
23+
24+
---
25+
26+
1527
### SpringMVC
1628

1729
**Стек:**

SpringBootStarter/build.gradle

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
plugins {
2+
id 'org.springframework.boot' version '2.5.0'
3+
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
4+
id 'java'
5+
}
6+
7+
8+
version '1.0-SNAPSHOT'
9+
10+
compileJava.options.encoding = "UTF-8"
11+
compileTestJava.options.encoding = "UTF-8"
12+
13+
repositories {
14+
mavenCentral()
15+
}
16+
17+
dependencies {
18+
19+
20+
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
21+
implementation 'org.springframework.boot:spring-boot-starter-web'
22+
testImplementation('org.springframework.boot:spring-boot-starter-test')
23+
implementation 'org.postgresql:postgresql:42.2.20'
24+
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper:9.0.46' // для отображения jsp приходится ее подсоединять
25+
26+
27+
compileOnly 'org.projectlombok:lombok:1.18.20'
28+
annotationProcessor 'org.projectlombok:lombok:1.18.20'
29+
implementation group: 'jstl', name: 'jstl', version: '1.2'
30+
implementation group: 'jstl', name: 'jstl', version: '1.2'
31+
32+
33+
// https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui
34+
implementation 'org.springdoc:springdoc-openapi-ui:1.6.7'
35+
36+
37+
}
38+
39+
40+
test {
41+
useJUnitPlatform()
42+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package ru.alon;
2+
3+
import org.springframework.boot.CommandLineRunner;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.boot.autoconfigure.domain.EntityScan;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
9+
import ru.alon.entity.Jedi;
10+
import ru.alon.repository.JediRepository;
11+
12+
13+
@SpringBootApplication
14+
@EnableJpaRepositories(value = "ru.alon.repository")
15+
@EntityScan("ru.alon.entity")
16+
public class Application {
17+
public static void main(String[] args) {
18+
SpringApplication.run(Application.class, args);
19+
}
20+
21+
@Bean
22+
public CommandLineRunner demo(JediRepository repository) {
23+
return (args) -> {
24+
repository.save(Jedi.builder().firstName("first").lastName("last").build());
25+
for (Jedi jedi :
26+
repository.findAll()) {
27+
System.out.println(jedi);
28+
}
29+
};
30+
}
31+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package ru.alon.entity;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
import javax.persistence.*;
9+
10+
@Data
11+
@NoArgsConstructor
12+
@AllArgsConstructor
13+
@Builder
14+
@Entity
15+
@Table(name = "jedi")
16+
public class Jedi {
17+
@Id
18+
@GeneratedValue(strategy = GenerationType.IDENTITY)
19+
private long id;
20+
@Column(name = "first_name")
21+
private String firstName;
22+
@Column(name = "last_name")
23+
private String lastName;
24+
25+
26+
27+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ru.alon.repository;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
import ru.alon.entity.Jedi;
5+
6+
public interface JediRepository extends JpaRepository<Jedi,Long> {
7+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# ===============================
2+
# DATABASE CONNECTION
3+
# ===============================
4+
5+
spring.datasource.driver-class-name=org.postgresql.Driver
6+
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
7+
spring.datasource.username=postgres
8+
spring.datasource.password=postgres
9+
10+
# ===============================
11+
# JPA / HIBERNATE
12+
# ===============================
13+
14+
spring.jpa.show-sql=true
15+
spring.jpa.hibernate.ddl-auto=update
16+
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
17+
18+
spring.mvc.view.prefix:/WEB-INF/views/
19+
spring.mvc.view.suffix:.jsp
20+
21+
logging.level.org.springframework.orm.jpa=DEBUG
22+
logging.level.org.springframework.transaction=DEBUG
23+
24+

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ rootProject.name = 'CourseWorkJavaEE'
22
include 'HiberModule'
33
include 'db'
44
include 'SpringMVC'
5+
include 'SpringBootStarter'
56

0 commit comments

Comments
 (0)