일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- GIT
- AWS
- node.js
- JaCoCo
- sanghaklee
- Gitbook
- Lodash
- Code-coverage
- primitive type
- Coveralls
- Travis CI
- javascript
- PowerMock
- NPM
- ubuntu
- REST
- nginx
- RESTful
- sinopia
- python
- ECMAScript2015
- Linux
- 개인정보수정
- dict
- {}
- java
- API
- 인프런
- Unit-test
- ATOM
- Today
- Total
이상학의 개발블로그
[Java] JAVA SPRING BOOT 기초 본문
2019.10.26 양재동 코드랩 JAVA SPRING BOOT 기초 #2의 정리
Embeded Tomcat 이용한 단독 실행
Spring Actuator: 모니터링과 관리
DB setting
create database codelab_db default character set utf8;
grant all privileges on codelab_db.* to codelab@localhost identified by 'codelab';
flush privileges;
오류
You must reset your password using ALTER USER statement before executing this statement.
mysql> set password = password('PASSWORD');
https://kogun82.tistory.com/122
실습 1
IntelliJ
Create Project - Spring initializr
New Project
Dependencies
Dev Tools -
lombok
WEB -
Spring Web
SQL -
Spring Data JPA, MySQL Driver
DB 연결 정보 셋팅
src
-main
-resources
application.properties 삭제
application.yml 만들기
spring:datasource:url: jdbc:mysql://127.0.0.1:3306/codelab_db?serverTimezone=Asia/Seoul&useSSL=false&characterEncoding=utf-8username: codelabpassword: codelabdriver-class-name: com.mysql.jdbc.Driverjpa:hibernate:ddl-auto: update # 없으면 만들고 있으면 그대로 사용show-sql: true # mysql debug mode, 실제 쿼리가 로그로 보임database-platform: org.hibernate.dialect.MySQL5InnoDBDialectproperties:hibernate: # custom optionsformat_sql: true # sql 로그를 포매팅해서 보여줌logging:level:org.hibernate.type: trace # bind 쿼리의 내용까지 출력. ? 부분이 실제 값으로 표현됨server:port: 8080
ddl-auto
update: 없으면 만들고 있으면 그대로 사용
create: 무조건 새로 만듦
기본 컨트롤러 작성
src
-main
-java
-kr.codelabs.member
package: controller
class: MyController
@RestController
@GetMapping
RUN!!
실습 2
DB
src
-main
-java
-kr.codelabs.member
Department
package: entity
class: Department
@Entity
@Table
@Getter
DepartmentRepository
package: repository
interface: DepartmentRepository
DepartmentService
package: service
interface: DepartmentService
DepartmentController
package: controller
class: DepartmentController
CRUD
GET
@PathVariable
@RequestParam
POST
@RequestBody
Member
Swagger
https://mvnrepository.com/artifact/io.springfox/springfox-swagger2
1. dependency 추가
pom.xml
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
config
package: config
class: SwaggerConfig
ApiOperation (각 컨트롤러)
swagger-ui
http://127.0.0.1:8080/swagger-ui.html
OAuth 인증 서버 구현
DB
src - main - resources
/data.sql
/schema.sql
application.yml
initialization-mode: always # spring 구동 시 resources 하위 .sql 실행
continue-on-error: true # 에러나도 실행. 개발에서만 사용
API 서버
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
dependency
spring-cloud-starter-oauth2
spring-cloud-starter-security
dependencyManagement
repositories
Spring Boot Actuator
https://www.baeldung.com/spring-boot-actuators
jconsole
$ jconsole
배포
사전에 maven 설치
$ mvn package
$ cd target # .jar 파일이 생성됨
$ java -jar NAME.jar
zard21@gmail.com
'교육 > 코드랩' 카테고리의 다른 글
[React / 코드랩] ReactJS와 NodeJS-Express를 이용한 웹 서비스 개발하기 (0) | 2016.08.29 |
---|