Tech/SpringBoot
-
java8-streamTech/SpringBoot 2016. 10. 13. 00:15
java8 의 stream 을 컬렉션에 적용 해보기: List wordList = new ArrayList();wordList.add("test");wordList.add("test");wordList.add("test");wordList.add("aooooasdasdao");wordList.add("aooooasdasdao");wordList.add("aooooasdasdao");long count = wordList.stream().count();long countByFilter = wordList.stream().filter(w->w.length()>5).count(); stream 은 wordList 의 stream 을 돌려준다.filter 는 5 보다 큰 단어만 담은 stream 을 리턴 한다...
-
java static initial block- 자바 초기화 블럭 사용법Tech/SpringBoot 2016. 2. 24. 16:56
용도: 클래스 변수 초기화와 인스턴스 변수의 초기화에 사용된다.인스턴스 변수의 초기화는 생성자보다 항상 먼저 실행 된다. 사용법: 클래스 초기화 는 static 키워드를 사용한다.'인스턴스 초기화는 블락{} 을 사용한다. example: class myInitBlock{ static { // 클래스 초기화 영역 } { // 인스턴스 초기화 영역 }} 예제 코드: public class StaticExample{ static { System.out.println("This is first static block"); } public StaticExample(){ System.out.println("This is constructor"); } public static String staticString = ..
-
spring boot jpa (mysql ) table 생성 에러해결Tech/SpringBoot 2015. 12. 26. 23:22
해당 에러는 다음과 같다. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'bigint not null auto_increment, email varchar(256) not null, enable integer not ' at line 1 위와같은 에러는 회원정보의 인덱스이름을 index 라고 하였기 때문에 mysql 의 index 와 중복이되어 발생 하였다. index -> idx 와 같은 다른 이름으로 변경시 해결됨.
-
자바 Check if some exe program is running on the windowsTech/SpringBoot 2015. 11. 6. 16:49
자바로 윈도우즈에서 실행 중인 프로그램 리스트 가져오기특정 프로그램에 대해 찾기 String line;String pidInfo =""; try {Process p =Runtime.getRuntime().exec(System.getenv("windir") +"\\system32\\"+"tasklist.exe"); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { pidInfo+=line; } input.close(); if(pidInfo.contains("powershell.exe")){ System.out.println("..
-
Spring boot - Sigar 사용( 시스템 모니터링)Tech/SpringBoot 2015. 11. 6. 12:06
자바에서 Sigar 라이브러리를 사용하여 시스템에 대해 모니터링 할 수있다. Sigar repository 를 사용하려고 하였으나 library path 문제로 실패 하였다. 실패 메시지 : org.hyperic.sigar.SigarException: no sigar-amd64-winnt.dll in java.library.path 수동으로 라이브러를 다운 받아 추가 하는 방식으로 한다. import org.hyperic.sigar.CpuPerc;import org.hyperic.sigar.Sigar;import org.hyperic.sigar.SigarException; public class SigarTest {public static void main(String[] args){// sigar 객체..
-
spring boot jpa(querydsl)Tech/SpringBoot 2015. 10. 20. 14:04
spring boot 에서 jpa 사용 기본적으로 제공되는 findByXXX, 와 같은 기능들은 문제없이 사용 된다. repository를 실제고 구현 해야 할때는 추가적으로 해야 할 설정이있다. ( 개인 적인 생각?) cusmtom repository 를 구현 하려면 데이터 소스에 대한 설정을 해주어한다. member jpa model : datasourceconfig: repository class 다이어그램 : repository 인터페이스를 구현 할 클래스의 이름은 무조건(?) 해당 repository + impl 을 붙여야 한다. 데모프로젝트 패키지 구조 : 해당 데모 프로젝트 소스 application.properties:spring.profiles.active=production#server..
-
Spring data jpa cascade 관련 오류Tech/SpringBoot 2015. 10. 15. 13:39
Caused by: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing 위와 같은 오류는 JoinColumn 에 대해 cascadeType을 설정 하지 않아 발생 한것이다. @OneToOne(cascade={CascadeType.ALL})@JoinColumn(name="relationID")
-
java grok patternTech/SpringBoot 2015. 10. 12. 13:59
파일에서 line by line 으로 문자열 리스트를 읽어온 후 해당 문자열 리스트들을 Grok 패턴의 정의에 따라 문자열 리스트 맵을 구성 할 수있는 함수이다. public List makeResultList(List strList, String expression)throws Exception {List resultList = new ArrayList();final GrokDictionary dictionary = new GrokDictionary();dictionary.addBuiltInDictionaries();dictionary.bind();Grok compiledPattern = dictionary.compileExpression(expression);if(strList !=null && !e..
-
디렉터리의 특정패턴의 파일 리스트 가져오기Tech/SpringBoot 2015. 10. 12. 13:54
// 해당 디렉토리의 특정 패턴으로 된 파일이름 리스트가져오기public String[] getFileList(String path,final String pattern){File file = new File(path);String fileList[] = file.list(new FilenameFilter(){@Overridepublic boolean accept(File dir, String name) {return name.startsWith(pattern);}});return fileList;}
-
spring boot 데몬 어플리케이션 만들기Tech/SpringBoot 2015. 9. 28. 12:46
스프링 부트로 syslog 를 분석하는 데몬 어플리케이션 을 만들어 보도록 한다. 가정: syslog message 에는 IPAddress,MacAddress,Time, JobType 관련 정보가 포함 되어있다.해당 메시지에서 ip 와 mac 주소,jobtype 을 추출하여 각 jobType 에 따라 처리하도록 한다. sts 로 spring start project 생성한다. dependency 에 대해서는 필요할 경우 추가하 면 되기 때문에 여기서는 그냥 skip... 생성된 데몬app 의 클래스 구조는 아래와 같다. springApplication클래스가 @SpringApplication을 사용하여 실행 하게 된다. @SpringApplication 은 설정 부터 시작하여 컴포넌트 스캔을 비롯한 각종..