- Embeded Tomcat 이용한 단독 실행
- Spring Actuator: 모니터링과 관리
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
- Create Project - Spring initializr
- New Project
- Dependencies
4. Dev Tools -
lombok
5. WEB -Spring Web
6. SQL -Spring Data JPA, MySQL Driver
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-8 username: codelab password: codelab driver-class-name: com.mysql.jdbc.Driver jpa: hibernate: ddl-auto: update # 없으면 만들고 있으면 그대로 사용 show-sql: true # mysql debug mode, 실제 쿼리가 로그로 보임 database-platform: org.hibernate.dialect.MySQL5InnoDBDialect properties: hibernate: # custom options format_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!!
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
@PathVariable
@RequestParam
@RequestBody
https://mvnrepository.com/artifact/io.springfox/springfox-swagger2
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>
- package: config
- class: SwaggerConfig
- ApiOperation (각 컨트롤러)
http://127.0.0.1:8080/swagger-ui.html
src - main - resources
/data.sql
/schema.sql
initialization-mode: always # spring 구동 시 resources 하위 .sql 실행
continue-on-error: true # 에러나도 실행. 개발에서만 사용
<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
https://www.baeldung.com/spring-boot-actuators
$ jconsole
사전에 maven 설치
$ mvn package
$ cd target # .jar 파일이 생성됨
$ java -jar NAME.jar