0405 - 0411


# 0405 - 0411

# 0405 - JPA Auditing

์ƒ์„ฑ์‹œ๊ฐ„/์ˆ˜์ •์‹œ๊ฐ„ ์ž๋™ํ™”

# @EnableJpaAuditing

  • JPA Auditing ํ™œ์„ฑํ™”
@EnableJpaAuditing
@SpringBootApplication
public class Application {
    ...
}

# @MappedSuperclass

  • JPA Entity ํด๋ž˜์Šค๋“ค์ด ํ•ด๋‹น ์ถ”์ƒ ํด๋ž˜์Šค๋ฅผ ์ƒ์†ํ•  ๊ฒฝ์šฐ ์ƒ์œ„ ์ปฌ๋Ÿผ๋“ค์„ ์ธ์‹

# @EntityListeners(AuditingEntityListener.class)

  • ํ•ด๋‹น ํด๋ž˜์Šค์— Auditing ๊ธฐ๋Šฅ์„ ํฌํ•จ
@Getter
@EntityListeners(AuditingEntityListener.class)
@MappedSuperclass
public abstract class BaseEntity {
    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss")
    @CreatedDate
    @Column(name = "created_at", columnDefinition = "timestamp with time zone", updatable = false)
    private LocalDateTime createdAt;

    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss")
    @LastModifiedDate
    @Column(name = "updated_at", columnDefinition = "timestamp with time zone")
    private LocalDateTime updatedAt;
}

# @CreatedDate

  • Entity ์ƒ์„ฑ ์ €์žฅ์‹œ ์‹œ๊ฐ„ ์ž๋™์ €์žฅ

# @LastModifiedDate

  • Entity์˜ ๊ฐ’ ๋ณ€๊ฒฝ์‹œ ์‹œ๊ฐ„ ์ž๋™์ €์žฅ

# 0406 - @RestController & @ExceptionHandler

# @ExceptonHandler


    @ExceptionHandler(NullPointerException.class)
    public String nullex(Exception e) { 
        return e.getMessage();
    } 
  • ExceptionHandler์˜ ๋งค์น˜ ๋ฒ”์œ„๋ฅผ ๊ฒฐ์ • ํ•  ์ˆ˜ ์žˆ๋‹ค.
    @ExceptionHandler(NullPointerException.class)

# @ControllerAdvice

@ExceptionHandler, @ModelAttribute, @InitBinder ๊ฐ€ ์ ์šฉ๋œ ๋ฉ”์„œ๋“œ๋“ค์„ AOP๋ฅผ ์ ์š”ํ•ด ์ปจํŠธ๋กค๋Ÿฌ ๋‹จ์— ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๊ณ ์•ˆ๋œ ์• ๋„ˆํ…Œ์ด์…˜

# @RestControllerAdvice

@ResponseBody + @ControllerAdvice : @RestControllerAdvice

  • @RestControllerAdvice์™€ @ExceptonHandler๋ฅผ ์‚ฌ์šฉํ•ด ์ปจํŠธ๋กค๋Ÿฌ ์ „์—ญ์œผ๋กœ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

# 0407 - rc-local.service

Centos 7 ๋ถ€ํŒ…์‹œ ๋ช…๋ น์–ด ์ž๋™์‹คํ–‰

# rc.local ํŒŒ์ผ

  • /etc/rc.d/rc.local
  • rc.local ์‹คํ–‰ ๊ถŒํ•œ ํ—ˆ์šฉ
    chmod +x /etc/rc.d/rc.local

# ์‹คํ–‰ ์Šคํฌ๋ฆฝํŠธ ์ถ”๊ฐ€

  • vi /etc/rc.d/rc.local
#!/bin/sh

touch /var/lock/subsys/local
su - user -c /home/app/run.sh

# ์„œ๋น„์Šค์„ค์ •

  • ์ƒํƒœํ™•์ธ
    systemctl status rc-local.service

  • ์‹คํ–‰
    systemctl start rc-local.service

  • ์„œ๋น„์Šค enable ์ฒ˜๋ฆฌ
    vi /usr/lib/systemd/system/rc-local.service

  • ์Šคํฌ๋ฆฝํŠธ ์ถ”๊ฐ€

[Install]
WantedBy=multi-user.target

# ํ™•์ธ

systemctl enable rc-local.service
systemctl status rc-local.service
systemctl list-unit-files | grep rc-local


# 0408 - Yaml

Yaml Ain't Markup Language

# vs Properties

  • Properties
example.jdbc.url=127.0.0.1 
example.jdbc.port=3306 
example.jdbc.user=user 
example.jdbc.password=password
  • yaml
example: 
  jdbc: 
    url: 127.0.0.1 
    port: 3306 
    user: user 
    password: password

=> ๊ณ„์ธต ๊ตฌ์กฐ๋ฅผ ์ž˜ ๋‚˜ํƒ€๋ƒ„

# vs JSON

  • JSON
{
  "json": [
    "rigid",
    "better for data interchange"
  ],
  "yaml": [
    "slim and flexible",
    "better for configuration"
  ],
  "object": {
    "key": "value",
    "array": [
      {
        "null_value": null
      },
      {
        "boolean": true
      },
      {
        "integer": 1
      }
    ]
  },
  "paragraph": "Blank lines denote\nparagraph breaks\n",
  "content": "Or we\ncan auto\nconvert line breaks\nto save space"
}
  • yaml
--- 
# <- yaml supports comments, json does not 
# did you know you can embed json in yaml? 
# try uncommenting the next line 
# { foo: 'bar' } 
json: 
  - rigid 
  - better for data interchange 
yaml: 
  - slim and flexible 
  - better for configuration 
object: 
  key: value 
  array: 
    - null_value: 
    - boolean: true 
    - integer: 1 
paragraph: > 
  Blank lines denote 
  
  
  paragraph breaks
content: |- 
  Or we 
  can auto 
  convert line breaks 
  to save space

# etc

servers:
  - www.abc.test.com
  - www.xyz.test.com

external: [www.abc.test.com, www.xyz.test.com] 
boolean_flag: true
warrent:
  ment: >
  johnber is
  very important

=> | ์ค„๋ฐ”๊ฟˆ, > ์ค„๋ฐ”๊ฟˆ ๋ฌด์‹œ


# 0409 - ๊ฐœ๋ฐœ์ž์˜ ํ‰์ƒ๊ณต๋ถ€

  1. ์ง€๊ธˆ ๋‹ค๋‹ˆ๊ณ  ์žˆ๋Š” ํšŒ์‚ฌ์—์„œ ํ•˜๋Š” ์ผ์„ ์ž˜ํ•˜๊ธฐ ์œ„ํ•ด์„œ ๋…ธ๋ ฅํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ์ข‹์€ ๊ณต๋ถ€๋‹ค.
  2. ํšŒ์‚ฌ์—์„œ ํ•˜๋Š” ์ผ๊ณผ ๊ฐœ์ธ์ ์œผ๋กœ ๊ณต๋ถ€ํ•˜๋Š” ๋‚ด์šฉ์„ ์ตœ๋Œ€ํ•œ ๊ทผ์ ‘์‹œํ‚ค๊ธฐ ์œ„ํ•ด์„œ ๋…ธ๋ ฅํ•˜๋ผ.
  3. ์ƒˆ๋กœ์šด ๊ธฐ์ˆ ์„ ์ตํžˆ๋Š” ์ตœ์„ ์˜ ๋ฐฉ๋ฒ•์€ ์Šค์Šค๋กœ ๋ฌธ์ œ๋ฅผ ์ •์˜ํ•œ ๋‹ค์Œ, ์ƒˆ๋กœ์šด ๊ธฐ์ˆ ์„ ์ด์šฉํ•ด์„œ ๊ทธ ๋ฌธ์ œ๋ฅผ ํ’€์–ด ๋ณด๋Š” ๊ฒƒ์ด๋‹ค. ์ฑ…์„ ์ฝ๊ฑฐ๋‚˜ ๋™์˜์ƒ์„ ๋ณด๋Š” ๊ฒƒ์€ ๊ทธ๋ณด๋‹ค ํ•˜์œ„์ˆ˜์ค€์˜ ๋ฐฉ๋ฒ•์ด๋‹ค.
  4. ์‹ ๊ธฐ์ˆ ์„ ์ซ’๋Š” ๋ฉ”๋šœ๊ธฐ๊ฐ€ ๋˜์ง€ ๋ง๋ผ.
  5. ๋ชจ๋“  ๊ฒƒ์„ ์•Œ์•„์•ผ ํ•œ๋‹ค๋Š” ๊ฐ•๋ฐ•์„ ๋ฒ„๋ ค๋ผ. ๋ฏธ๋ฆฌ ํš๋“ํ•˜๋Š” ์ง€์‹์˜ 99%๋Š” ๋ฌด์šฉ์ง€๋ฌผ์ด๋‹ค. ํ•„์š”ํ•  ๋•Œ ํ•„์š”ํ•œ ๊ธฐ์ˆ ์„ ์ตํž ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด ๋Šฅ๋ ฅ์ด๋‹ค. ๊ทธ ๋Šฅ๋ ฅ์„ ํ‚ค์›Œ๋ผ.
  6. ์ด์ƒํ•œ ๋‚˜๋ผ์˜ ์—˜๋ฆฌ์Šค์— ๋‚˜์˜ค๋Š” ํ† ๋ผ๊ตด์„ ํ”ผํ•ด๋ผ. ์นดํ…Œ๊ณ ๋ฆฌ์ด๋ก ์„ ์•Œ์•„์•ผ ํ•จ์ˆ˜ํ˜• ์–ธ์–ด๋ฅผ ์“ธ ์ˆ˜ ์žˆ๋Š”๊ฒŒ ์•„๋‹ˆ๊ณ , ์„ ํ˜•๋Œ€์ˆ˜ํ•™์„ ๊ณต๋ถ€ํ•ด์•ผ ๋จธ์‹ ๋ ๋‹์„ ํ•  ์ˆ˜ ์žˆ๋Š”๊ฒŒ ์•„๋‹ˆ๋‹ค. ํ† ๋ผ๊ตด์— ๋น ์ ธ์„œ ํ•œ์—†์ด ๋“ค์–ด๊ฐ€๋‹ค๋ณด๋ฉด ๋น„๋ณธ์งˆ์ ์ธ ๊ณต๋ถ€์— ์‹œ๊ฐ„์„ ํ—ˆ๋น„ํ•˜๊ฒŒ ๋œ๋‹ค.
  7. ๊ฒ‰๋งŒ ํ•ฅ๋Š” ๊ฒƒ์€ ๊ฒฝ๋ฐ•ํ•˜์ง€๋งŒ ํ† ๋ผ๊ตด์— ๋น ์ง€๋Š” ๊ฒƒ์€ ์šฐ๋งคํ•˜๋‹ค. ๋‘˜ ์‚ฌ์ด์˜ ์ ๋‹นํ•œ ์ง€์ ์—์„œ ๊ท ํ˜•์„ ์žก๋Š” ๊ฒƒ์ด ๊ฐœ๋ฐœ์ž์˜ ๋Šฅ๋ ฅ์ด๋‹ค.
  8. ๋จธ๋ฆฌ์— ๋“ค์–ด์˜ค์ง€ ์•Š๋Š” ์–ด๋ ค์šด ๊ฐœ๋…์ด๋‚˜ ์šฉ์–ด๋Š” ์žํˆฌ๋ฆฌ ์‹œ๊ฐ„์„ ์ด์šฉํ•ด์„œ ๋ฐ˜๋ณต์ ์œผ๋กœ ์ผ๊ณ  ์•”๊ธฐํ•˜๋ผ. ๋‚˜์ค‘์— ํฐ ๊ทธ๋ฆผ์„ ๊ณต๋ถ€ํ•  ๋•Œ ๋„์›€์ด ๋œ๋‹ค.
  9. ํ•ญ์ƒ ๊ฒธ์†ํ•ด์•ผ ํ•˜์ง€๋งŒ ๋™์‹œ์— ์ž๊ธ์‹ฌ์„ ๊ฐ€์ ธ๋ผ. ๊ทธ๋Œ€๊ฐ€ ์ง€๊ธˆ ์ž‘์„ฑํ•œ ์ฝ”๋“œ, ์ง€๊ธˆ ์ฝ์€ ์ฑ…, ์ง€๊ธˆ ๊ณต๋ถ€ํ•œ ๋‚ด์šฉ์„ ๊ทธ๋Œ€๋ณด๋‹ค ์ž˜ ์•„๋Š” ์‚ฌ๋žŒ์€ ์ง€๊ตฌ์ƒ์— ์—†๋‹ค. ๋ชจ๋“ ๊ฑธ ์•Œ๊ณ  ์žˆ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด๋Š” ๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค๋„ ๊ทธ๋Œ€์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋ถˆ์•ˆํ•ดํ•˜๊ณ , ์œ„์ถ•๋˜๊ณ , ๋‘๋ ค์›Œํ•˜๋ฉด์„œ ์‚ด์•„๊ฐ€๊ณ  ์žˆ๋‹ค. ์ž๊ธ์‹ฌ์ด๋ž€ ๊ทธ๋Ÿฐ ํƒ€์ธ์„ ๋•๊ณ ์ž ํ•˜๋Š” ๋งˆ์Œ๊ฐ€์ง์˜ ๋‹ค๋ฅธ ์ด๋ฆ„์ด๋‹ค.

์›๊ธ€:๊ฐœ๋ฐœ์ž์˜ ํ‰์ƒ๊ณต๋ถ€ (opens new window)


# 0410 - ๋‚ด ํฌํŠธ ํด๋ฆฌ์˜ค๊ฐ€ ์„œ๋ฅ˜ํƒˆ๋ฝ์ธ ์ด์œ 

# ํ”„๋กœ์ ํŠธ ์ž๊ฐ€์ง„๋‹จ

์•ž์œผ๋กœ ๋ฐฉํ–ฅ์„ฑ์— ๋Œ€ํ•œ ์ง„๋‹จ

  • ์‹ค์ œ ์„œ๋น„์Šค๋ฅผ ๊ณต๊ฐœ์ ์œผ๋กœ ๋ฐฐํฌํ•˜๊ณ  ์šด์˜ํ•ด๋ณด๋Š” ๊ฒฝํ—˜
  • ์œ ์ €์˜ ํ”ผ๋“œ๋ฐฑ์— ๋”ฐ๋ผ ์„ฑ๋Šฅ/์‚ฌ์šฉ์„ฑ์„ ๊ฐœ์„ ํ•˜๊ณ  ์‹ ๊ทœ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€
  • ๋ฐœ๊ฒฌ๋˜๋Š” ๋ฒ„๊ทธ์™€ ๊ฐœ์„ ์‚ฌํ•ญ์„ ์ •๋ฆฌํ•˜๊ณ  ์Œ“์ธ ์ด์Šˆ๋“ค์„ ์ฒด๊ณ„์ ์œผ๋กœ ๊ด€๋ฆฌ
  • ์ฝ”๋“œ๋ฅผ ์ง€์†์ ์œผ๋กœ ๋ฆฌํŽ™ํ† ๋งํ•˜๊ณ  ๋””์ž์ธํŒจํ„ด์„ ์ ์šฉํ•˜๊ธฐ
  • ์œ„์˜ ์‹œ๋„์—์„œ ๋” ์ข‹์€ ์„ค๊ณ„์™€ ๋” ๋น ๋ฅธ ๊ฐœ๋ฐœ ์‚ฌ์ด์˜ ํŠธ๋ ˆ์ด๋“œ์˜คํ”„๋ฅผ ๊ณ ๋ฏผํ•ด๋ณด๊ธฐ
  • ๋ฐ˜๋ณต๋˜๋Š” ์ˆ˜์ •๊ณผ ๋ฐฐํฌ์— ์ˆ˜๋ฐ˜๋˜๋Š” ์ž‘์—…๋“ค์„ ์ž๋™ํ™”ํ•ด๋ณด๊ธฐ
  • ์–ธ์–ด๋‚˜ ํ”„๋ ˆ์ž„์›Œํฌ์˜ ๊ธฐ๋Šฅ๋งŒ์œผ๋กœ ๊ตฌํ˜„ ํ•  ์ˆ˜ ์—†๋Š” ๊ฒƒ๋“ค์„ ์ง์ ‘ ๊ตฌํ˜„ํ•ด๋ณด๊ธฐ
  • ๋‚ด๊ฐ€ ์‚ฌ์šฉํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋‚˜ ํ”„๋ ˆ์ž„์›Œํฌ์˜ ๋ฌธ์ œ์ ์ด๋‚˜ ํ•œ๊ณ„๋ฅผ ๊ฐœ์„ ํ•ด๋ณด๊ธฐ
  • ์ฝ”๋“œ๋‚˜ ์ œํ’ˆ์˜ ํ€„๋ฆฌํ‹ฐ๋ฅผ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•œ ๋ถ„์„ํˆด์ด๋‚˜ ํ…Œ์ŠคํŠธํˆด์„ ๋„์ž…ํ•ด๋ณด๊ธฐ
  • ํƒ€์ธ๊ณผ์˜

# ๊ฒฐ๋ก 

์—ฌ๋Ÿฌ ์–ธ์–ด์™€ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ๊ธ‰ํ•˜๊ฒŒ ์ตํ˜€์„œ ์ด๊ฑฐ์ €๊ฑฐ ํ† ์ดํ”„๋กœ์ ํŠธ๋ฅผ ์ฐ์–ด๋‚ด๋Š” ๊ฒƒ๋„ ์ข‹์ง€๋งŒ, ํ”„๋กœ์ ํŠธ๋ฅผ ์‹ค์ œ๋กœ ์šด์˜ํ•ด๋ณด๊ณ  ๊ณ ๋„ํ™” ํ•˜๊ณ  ํ™•์žฅํ•ด๋‚˜๊ฐ€๋Š” ๊ฒฝํ—˜๋„ ์ค‘์š”ํ•˜๋‹ค. ์ด๋ฅผ ์œ„ํ•ด ์ˆ˜๋ฐ˜๋˜์–ด์•ผ ํ•  ์ž‘์—…๋“ค์„ ์ง์ ‘ ์•Œ์•„๊ฐ€๋ฉฐ ๋„์ž…ํ•ด๋ณด๋Š” ๊ฒฝํ—˜๋„ ํ•„์š”ํ•˜๋‹ค.

์›๊ธ€:๋‚ด ํฌํŠธํด๋ฆฌ์˜ค๊ฐ€ ์„œ๋ฅ˜ํƒˆ๋ฝ์ธ ์ด์œ  - ํ”„๋กœ์ ํŠธ ์ด๋ ‡๊ฒŒ ํ•ด๋ณด์„ธ์š” (opens new window)

Last update: September 13, 2022 21:44
Contributors: ahnjs , jaesungahn91