기본 콘텐츠로 건너뛰기

Integer - java

최대 최소값 최소 -2의 31승 / 최대 2의 31승-1 @Native public static final int MIN_VALUE = 0x80000000 ; @Native public static final int MAX_VALUE = 0x7fffffff ; toString() - 10진수를 다른진법으로, 문자열로 변환 Integer . toString ( 10 ) // 10 Integer . toString ( 10 , 2 ) // 1010 Integer . toString ( 10 , 5 ) // 20 toBinaryString(), toOctalString, toHexString() 자주사용하는 2진수, 8진수, 16진수는 별도함수가 있다. Integer . toBinaryString ( num ) // 1010 Integer . toOctalString ( num ) // 12 Integer . toHexString ( num ) // a valueOf() IntegerCache 사용(-128~127) cache범위가 벗어날때는 새로운 Integer객체를 생성 public static Integer valueOf ( int i ) { if ( i >= IntegerCache . low && i <= IntegerCache . high ) return IntegerCache . cache [ i + ( - IntegerCache . low ) ] ; return new Integer ( i ) ; } equals() 타입이 Integer인지, 값이 같은지 public boolean equals ( Object obj ) { if ( obj instanceof Integer ) { return value == ( (...

스프링부트, logging

Logging 스프링부트는 Java Util Logging, Log4j2, Logback을 기본적으로 제공한다. 내부적으로 apache common logging 을 사용하나 변경이 가능하다 만약 ‘Starters’를 사용한다면 Logback이 사용된다. Log Format 시간/로그레벨/process id/ 구분자(—)/ thread 명/ logger 명 / 메세지 2014-03-05 10:57:51.112 INFO 45469 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.52 2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1358 ms Color-coded Output 로그에 색을 입힐 수도 있다. spring.output.ansi.enabled 값을 설정해주면 된다. Enum Constants Enum Constant Description ALWAYS Enable ANSI-colored output. DETECT Try to detect whether ANSI coloring capabilities are available. NEVER Disable ANSI-colored output. File Output 기본적으로 스프링 부트는 파일에는 로그를 남기지 않고 콘솔에만 표시한다. ...

스프링부트, Externalized Configuration

환경변수 설정 설정파일을 어플리케이션 밖에서 관리함으로써 같은 어플리케이션으로 여러가지 설정을 변경하면서 운영할 수 있다. Properties files, yaml files, environment variable, command-line arguments 사용 @Value 어노테이션을 통해 주입받을 수 있다. 우선순위 스프링부트에서는 환경변수값을 읽는 우선순위가 있다. 만약 예사외의 값이 적용되었다면 아래 순위를 확인해보자 devtools -> test관련 -> command line -> servlet -> Jndi -> system property -> environments -> random -> properties file -> @Configuration classes 1. [Devtools global settings properties](https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-devtools-globalsettings) on your home directory (~/.spring-boot-devtools.properties when devtools is active). 2. [@TestPropertySource](https://docs.spring.io/spring/docs/5.0.5.BUILD-SNAPSHOT/javadoc-api/org/springframework/test/context/TestPropertySource.html) annotations on your tests. 3. [@SpringBootTest#properties](https://docs.spring.io/spring-boot/docs/2.0.1.BUILD-SNAPSHOT/api/org/springframework/boot/test/context/Spr...

스프링부트, SpringApplication 클래스

springApplication SpringApplication 스프링 어플리케이션을 간편하게 실행할 수 있도록 제공하는 클래스 main()함수를 통해 실행되며, 기본 로그 수준은 info 이다. The following example shows potential logging settings in application.properties: logging.level.root=WARN logging.level.org.springframework.web=DEBUG logging.level.org.hibernate=ERROR FailureAnalyzers 스프링 실행시 오류가 발생하면 에러메세지와 해결 방법을 제시해준다. \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* APPLICATION FAILED TO START \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Description: Embedded servlet container failed to start. Port 8080 was already i n use. Action Identify and stop the process that's listening on port 8080 or configure this application to listen on another port. customizing the Banner 스프링 실행시에 로딩되는 배너를 수정할 수 있다. classpath에 존재하는 banner.txt를 수정 (spring.banner.location) 텍스트 파일 대신에 이미지도 가능하다 (spring.banner.image.location) 스프링 부트 생성기 https://devops.datenkollektiv.de/banner.txt/index.html SpringA...

스프링부트, spring-boot-devtools

스프링부트에서 소스코드 수정시 자동으로 서버를 재시작 하는 기능등을 제공한다. maven dependencies < dependencies > < dependency > < groupid > org.springframework.boot </ groupid > < artifactid > spring-boot-devtools </ artifactid > < optional > true </ optional > </ dependency > </ dependencies > 자동 restart classpath가 변경되면 어플리케이션이 자동으로 restart ide마다 차이가 좀 있는데 eclipse는 저장시에 classpath 변경이 발생하지만, intellij는 build project 기능을 통해 진행된다. Restart vs Reload spring boot는 2개의 classloader를 사용 Base classloader : 변하지 않는 3rd party용 .jar파일같은 Restart classloader : 개발자가 직접 작성하는 클래스 같은 Restart 실행시에 base classloader가 미리 작업한 부분은 할필요하고 없으므로 효율적임 만약 restart 가 충분히 빠르지 못하게 작동한다면 JRebel의 reloading을 고려 Excluding Resources /META-INF/maven, /META-INF/resources, /resources, /static, /public, or /templates 이곳 폴더들은 변경이 일어나도 restart가 발생하지 않음 spring.devtools.restart.exclude= static /**,public/** 이런식으로 추가로 설정가능 Watching...

elasticsearch cors문제

~/config/elasticsearch.yml 파일 열고 아래 추가 http.cors.enabled : true http.cors.allow-origin: "*" http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE http.cors.allow-headers : "X-Requested-With,X-Auth-Token,Content-Type, Content-Length, Authorization"

챗봇 시작하기 (Azure bot-service , qna maker)

챗봇은 크게 두가지가 있다. 인공지능을 쓰느냐 인공지능을 안 쓰느냐 인공지능을 쓰면 당연히 좋을텐데, 머신런닝도 할 줄모르는 상황에서는 그림의 떡이다. 그럼 포기해야되나 싶지만, 굳이 그러지 않아도 된다. 사용성 과연 챗봇을 가지고 무얼할지를 조금 더 고민해보자. faq정도 읊어주고, 간단하게 몇가지 동작만 해주는걸로 충분하다면 굳이 인공지능이 필요할까? 비용적인 부분에서도 별로 효율적이지 못하다. 그럼 어떻게? 어떻게 구현을 해야되나 머릿속으로 그려보면, if문 몇개 추가하면 되지 싶다. '이런질문이 들어오게 유도하고' '이런대답을 해주면 된다' 쉽게생각하면 한없이 쉽다. 그런데 구현 마저도 쉽게 할수 있는 서비스들이 너무 많다. QnAMaker, Botservice 연동 여기서는 이 MicroSoft에서 제공하는 두가지 서비스를 활용하는 방법이다. 너무 쉬워서 어의가 없을 수도 있다. 0. 마이크로소프트 계정생성  ms계정이 있어야한다. 뒤늦게 말에서 좀 그렇긴한데, 무료가 아니다. 그렇다고 엄청 비싸지도 않다. 1. 계정을 만들고 portal.azure.com  에 접속 2. BotService 생성  - 새로 만들기 -> Bot Service 선택 -> 만들기  - 대충 봇이름 정도만 입력하면 된다. 3. BotService설정  - 2번에서 만들고 나면 포탈홈에 서비스명이 노출된다. 클릭해서 들어오자  - 봇서비스도 나름 소스코드다 c#, node.js 중에 편한걸로 선택하고, Question and Answer 템플릿을 선택한다. (어기서는  c#선택, 본인은 c#을 한번도 해본적이 없다) 4.  id , password 생성  - next버튼을 클릭하면 요런 화면이 나오는데, 파란색 버튼을 클릭하면 아이디와 암호를 발급받을 수 있다. 암호는 한번밖에...