'ITWeb/개발일반'에 해당되는 글 489건

  1. 2021.09.30 [ngrinder] groovy script 작성 참고 문서.
  2. 2021.09.27 [SpringBoot] Application 실행 시 특정 작업 실행 시키기
  3. 2021.09.16 [SpringBoot] 깡통 프로젝트 생성 후 실행 시 에러 (Error creating bean with name 'dataSource' defined in class path resource)
  4. 2021.09.15 [Gradle] 6.x 에서 7.x 로 넘어 오면서 runtime, compile.
  5. 2021.09.14 [Java] List 중복 제거.
  6. 2021.09.07 [ZSH] oh-my-zsh 설정 on Macbook.
  7. 2021.09.06 [wget] proxy 설정 사용.
  8. 2021.08.18 [Java] html strip + multi whitespace strip
  9. 2021.08.09 [MySQL] HikariCP Connection Pool 관리 예.
  10. 2021.08.02 [Log4J2] Executable Jar + Springboot framework 사용 예.

[ngrinder] groovy script 작성 참고 문서.

ITWeb/개발일반 2021. 9. 30. 12:43

https://github.com/naver/ngrinder/wiki/Groovy-Script-Structure

참고해서 작성 하면 되겠습니다.

 

http://naver.github.io/ngrinder/

 

 

 

:

[SpringBoot] Application 실행 시 특정 작업 실행 시키기

ITWeb/개발일반 2021. 9. 27. 12:39

아래 세 가지 방법으로 실행 시킬 수 있습니다.

@Component
public class RunAfterApplicationStart implements ApplicationRunner {

    @Override
    public void run(ApplicationArguments args) {
        // 실행 코드
    }
}

@Component
public class RunAfterApplicationStart implements CommandLineRunner {

    @Override
    public void run(String... args) {
        // 실행 코드
    }
}

@Component
public class RunAfterApplicationStart {

    @EventListener(ApplicationReadyEvent.class)
    public void hello() {
        // 실행 코드
    }
}

 

:

[SpringBoot] 깡통 프로젝트 생성 후 실행 시 에러 (Error creating bean with name 'dataSource' defined in class path resource)

ITWeb/개발일반 2021. 9. 16. 17:26

springboot 프로젝트 만들어야 할 때 이용 합니다.

https://start.spring.io/

필요한 dependency 추가해 주고 로컬로 다운로드 받아 바로 실행 시켜 봅니다.

근데 깡통임에도 불구하고 에러가 발생을 했습니다.

 

mybatis 를 추가 했을 경우 application.yml 에 datasource 관련 설정을 하지 않게 되면 발생 하는 에러 입니다.

아래와 같이 설정을 추가 하고 build.gradle 에 mysql connector lib 도 추가해 주고 실행 하면 에러가 없어 집니다.

 

[error logs]
2021-09-16 17:24:18.201  WARN 76669 --- [  restartedMain] ConfigServletWebServerApplicationContext : 
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: 
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: 
Factory method 'dataSource' threw exception; 
nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: 
Failed to determine a suitable driver class
2021-09-16 17:24:18.205  INFO 76669 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]

[application.yml]
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/...
    username: ${USER}
    password: ${PASSWORD}
    
[build.gradle]
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.26'

 

:

[Gradle] 6.x 에서 7.x 로 넘어 오면서 runtime, compile.

ITWeb/개발일반 2021. 9. 15. 17:51

아래와 같이 변경 해서 사용 하면 됩니다.

- Gradle 6.x 에서 Gradle 7.x 로 넘어 오면서 runtime, compile.
[6.x]
task copyDependencies(type: Copy) {
  into "$buildDir/libs/deps"
  from configurations.runtime
}

[7.x]
task copyDependencies(type: Copy) {
  into "$buildDir/libs/deps"
  from configurations.runtimeClasspath
}

[6.x]
jar {
  manifest {
    attributes 'Main-Class': 'Main.class',
        'Class-Path': configurations.compile.files.collect { "deps/$it.name" }.join(' ')
  }

  archiveName 'dictionary.jar'
  from {
    configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
  }
}

[7.x]
jar {
  manifest {
    attributes 'Main-Class': 'Main.class',
        'Class-Path': configurations.compileClasspath.files.collect { "deps/$it.name" }.join(' ')
  }

  archiveName 'dictionary.jar'
}

 

:

[Java] List 중복 제거.

ITWeb/개발일반 2021. 9. 14. 12:34

DictionaryModel 은 String, List<String> 맴버 변수를 가집니다.

이 맴버 변수 중 List<String> 을 모두 펼쳐서 distinct word 목록을 만들려고 합니다.

 

List<String> flats = new ArrayList<>();
List<String> words = new ArrayList<>();

for (DictionaryModel d : dictionarys ) {
	words.addAll(d.getAnalyzed());
}

flats = words.stream().distinct().collect(Collectors.toList());

기억력을 돕기 위해 기록해 봅니다.

 

:

[ZSH] oh-my-zsh 설정 on Macbook.

ITWeb/개발일반 2021. 9. 7. 10:47

또 뭔가 찾기 귀찮아서 기록해 봅니다.

 

[oh-my-zsh 설치]
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

 

[iTerm2 Color Schemes]
https://github.com/mbadolato/iTerm2-Color-Schemes/tree/master/schemes

 

[d2font 설치] (서체관리자 추가 및 iTerm 추가)
https://github.com/naver/d2codingfont

 

[highlighting]
$ brew install zsh-syntax-highlighting

$ vi .zshrc 하단에 추가
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

 

[Insecure Directory Skip]

$ vi .zshrc 제일 윗줄에 추가

 ZSH_DISABLE_COMPFIX=true

 

[Theme 수정]

$ vi .zshrc 수정 및 추가

ZSH_THEME="agnoster"
...중략...
prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]];
  then
  	prompt_segment black default "%(!.%{%F{yellow}%}.)$USER"
  fi
}

 

[newline 추가]

$ vi ~/.oh-my-zsh/themes/agnoster.zsh-theme

build_prompt() {
  RETVAL=$?
  prompt_status
  prompt_virtualenv
  prompt_aws
  prompt_context
  prompt_dir
  prompt_git
  prompt_bzr
  prompt_hg
  prompt_newline # <-- 추가
  prompt_end
}

 

[newline & multiline 적용]

PROMPT='%{%f%b%k%}$(build_prompt) '

# 아래 6, 7번 라인은 아래와 같이 작성을 하셔야 정상적으로 나옵니다.
prompt_newline() {
  if [[ -n $CURRENT_BG ]]; then
    echo -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR
%{%k%F{blue}%}$SEGMENT_SEPARATOR"
  else
    echo -n "%{%k%}"
  fi

  echo -n "%{%f%}"
  CURRENT_BG=''
}

 

[plugin 적용]

- zsh-syntax-highlighting

$ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

 

- zsh-autosuggestions

$ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

 

$ vi .zshrc

plugins=(
  git
  zsh-syntax-highlighting
  zsh-autosuggestions
  web-search
  jsontools
  macports
  node
  osx
  sudo
  docker
  iterm2
)
:

[wget] proxy 설정 사용.

ITWeb/개발일반 2021. 9. 6. 20:11

Proxy 사용 시 wget 에서도 설정을 해 줄 수 있습니다.

아래와 같이 사용 하시면 됩니다.

 

[general]

$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.14.1-darwin-x86_64.tar.gz

 

[http]

$ wget -e use_proxy=yes -e http_proxy=proxy.abcdefg.com:8080 http://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.14.1-darwin-x86_64.tar.gz

 

[https]

$ wget -e use_proxy=yes -e https_proxy=proxy.abcdefg.com:8080 https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.14.1-darwin-x86_64.tar.gz

:

[Java] html strip + multi whitespace strip

ITWeb/개발일반 2021. 8. 18. 11:30
content = content.replaceAll("<[^>]*>", "");  // html strip
content = content.replaceAll("( )+", " " );   // multi whitespace to single whitespace

사용할 일이 있는데 기억력이 떨어져서 기록 해 봅니다.

:

[MySQL] HikariCP Connection Pool 관리 예.

ITWeb/개발일반 2021. 8. 9. 08:12

 

HikariCP 를 사용하고 있는데 Connection Pool 에 대한 반납과 재사용이 원활 하지 않을 때가 있습니다.

Application 내부에서 사용과 반납을 너무 빈번하게 하고 있을 경우 이런 문제가 발생 하는 것 같습니다.

보통은 별 문제 없이 사용을 했으나 이런 문제가 발생 한다면 명시적으로 Close 를 해주고 다시 Connection 을 생성해 주면 문제를 해소 할 수 있습니다.

 

기억하기 위해 기록 합니다.

 

    config.setDriverClassName("com.mysql.cj.jdbc.Driver");
    config.setJdbcUrl("jdbc:mysql://....");
    config.setUsername(user);
    config.setPassword(pwd);
    config.setMaximumPoolSize(maxPoolSize);
    config.setMinimumIdle(minimumIdle);
    config.setConnectionTimeout(30000);
    config.setValidationTimeout(10000);
    config.setConnectionTestQuery("SELECT 1");
    config.addDataSourceProperty("autoReconnect", "true");
    config.addDataSourceProperty("serverTimezone", "Asia/Seoul");
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    config.addDataSourceProperty("dataSource.useServerPrepStmts", "true");
    config.addDataSourceProperty("characterEncoding","utf8");
    config.addDataSourceProperty("useUnicode","true");
    
    this.ds = new HikariDataSource(config);

 

getConnection() 은 pool 에서 얻어 옵니다.

getConnection().close() 하면 pool 을 반납 하게 됩니다. 

 

근데 이게 반납과 재사용이 잘 안된다. 그러면 ds.close() 하고 다시 connection 을 생성 합니다. (HikariDataSource ds)

 

:

[Log4J2] Executable Jar + Springboot framework 사용 예.

ITWeb/개발일반 2021. 8. 2. 20:45

 

springboot framework 을 이용해서 executable jar 구현 시 log4j2 사용 예)
- @Slf4j 사용
- logback.xml 사용
- -Dlogback.configurationFile=$DIR_HOME/logback.xml

로그가 중복으로 남을 경우)
https://logging.apache.org/log4j/2.x/manual/configuration.html#Additivity
- <logger name="..." ... additivity="false" />
- 단순하게 보면, Logger 에 선언 된 appender 로 한번 기록하고 root logger 에 의해서 한번 기록 하게 되는 구조 입니다.

build.gradle 예)
configurations.all {
  exclude module: 'spring-boot-starter-logging'
}
...중략...
dependencies {
...중략...
  compile group: 'org.slf4j', name: 'slf4j-api', version: "${props.getProperty('slf4j')}"
  compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: "${props.getProperty('log4j')}"
  compile group: 'ch.qos.logback', name: 'logback-classic', version: "${props.getProperty('logback')}"
  compile group: 'ch.qos.logback', name: 'logback-core', version: "${props.getProperty('logback')}"
...중략...
}

 

: